Saturday, 4 May 2024
Friday, 3 May 2024
Tuesday, 23 November 2021
Extent Report Nunit
using AventStack.ExtentReports;
using AventStack.ExtentReports.Reporter;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Edge;
using System.Diagnostics;
using System.Threading;
using WebDriverManager;
using WebDriverManager.DriverConfigs.Impl;
namespace TestProject1
{
public class Tests
{
private IWebDriver IDriver;
ExtentHtmlReporter html;
ExtentReports extent;
ExtentTest test;
[OneTimeSetUp]
public void onetime()
{
html = new ExtentHtmlReporter(@"C:\Users\guest_at6naoe\source\repos\TestProject1\TestProject1\report.html");
html.LoadConfig(@"C:\Users\guest_at6naoe\source\repos\TestProject1\TestProject1\html-config.xml");
extent = new ExtentReports();
extent.AttachReporter(html);
}
[OneTimeTearDown]
public void onetimetd()
{
extent.Flush();
}
[SetUp]
public void SetUp()
{
IDriver = new ChromeDriver();
test=extent.CreateTest(TestContext.CurrentContext.Test.MethodName);
}
[TearDown]
public void TearDown()
{
IDriver.Quit();
}
[Test]
public void Google()
{
for (int i = 0; i < 3; i++) {
IDriver.Url = "https://www.google.com";
IDriver.FindElement(By.Name("q")).SendKeys("hi");
Thread.Sleep(4000);
var node = test.CreateNode("Node=>"+i);
node.Pass("opened google");
}
}
[Test]
public void Google2()
{
for (int i = 0; i < 3; i++)
{
IDriver.Url = "https://www.google.com";
IDriver.FindElement(By.Name("q")).SendKeys("loce");
Thread.Sleep(4000);
var node = test.CreateNode("Node=>" + i);
if (i == 2)
{
node.Fail("opened rediff");
}
else {
node.Pass("opened rediff");
}
}
}
}
}
//Config::
<?xml version="1.0" encoding="UTF-8"?>
<extentreports>
<configuration>
<!-- report theme -->
<!-- standard, dark -->
<theme>standard</theme>
<!-- enables timeline -->
<!-- defaults to true -->
<enableTimeline>true</enableTimeline>
<!-- document encoding -->
<!-- defaults to UTF-8 -->
<encoding>UTF-8</encoding>
<!-- protocol for script and stylesheets -->
<!-- defaults to https -->
<protocol>https</protocol>
<!-- title of the document -->
<documentTitle>Extent Framework</documentTitle>
<!-- report name - displayed at top-nav -->
<reportName>Build 1</reportName>
<!-- custom javascript -->
<scripts>
<![CDATA[
$(document).ready(function() {
});
]]>
</scripts>
<!-- custom styles -->
<styles>
<![CDATA[
]]>
</styles>
</configuration>
</extentreports>
Sunday, 29 December 2019
Iterator in Java
import java.util.ArrayList;
import java.util.Iterator;
public class ListIteratorDemo {
public static void main(String[] args) {
ArrayList<String> al = new ArrayList<String>();
for (int i = 0; i < 5; i++) {
al.add(i + " item ");
}
Iterator il = al.iterator();
// #Printing all elements
while (il.hasNext()) {
System.out.println(il.next());
}
System.err.println("________________________");
//Printing element based on condition
Iterator il2 = al.iterator();
while (il2.hasNext()) {
String str = (String) il2.next();
if (str.contains("4")) {
System.out.println(str);
}
}
}
}
/*OUTPUT########################################3
0 item
1 item
2 item
3 item
4 item
________________________
4 item
*/
ArrayList in Java
import java.util.ArrayList;
public class ArrayListDemo {
public static void main(String[] args) {
/*ArrayList
1. Best for item retrieval
2. Worst for inserting item in the middle. LinkedList best for middle insertion.
3. Implements Random Access Interface which allows any index access with same speed
4. NOT THREAD SAFE. Multiple threads can access simultaneously. With Collections class thread safety can be achieved
5. ArrayList<String> al=new ArrayList<String>();
Creates empty array list with default initial capacity 10
When arrayList reaches its maximum capacity new array list is created.Old elements are copied into it and references moved.
new capacity=(current capacity *3/2)+1
*/
ArrayList<String> al=new ArrayList<String>();
System.out.println(al.size()); //0 Physical Size 0 as no item added
System.out.println(al.isEmpty()); //true Since List is empty
System.out.println(al.add("first")); //true Will add item at 0 index as first item
System.out.println(al.isEmpty()); //false Since List is not empty now
System.out.println(al.size()); //1 Physical Size
al.add(1, "sagar"); // Add "sagar" at index 1
System.out.println(al.size()); //2 Since 2 items now with index 0 and 1
System.out.println(al); //[10, sagar]
al.add(1, "Sumit");
System.out.println(al); ; // [10, Sumit, sagar] Adding new element "Sumit" SHIFTS the list to right
/*
* Now list has two items (0,1) and we are trying to add value to index 3
* al.add(4,"test"); //Exception in thread "main"
* java.lang.IndexOutOfBoundsException: Index: 3, Size: 2
*
*/
/* Adding int data in String type arrayList will result in exception
System.out.println(al.add(10)); //Exception
The method add(int, String) in the type ArrayList<String> is not applicable for the arguments (int)
*/
System.out.println(al.contains("10")); //true
System.out.println(al.contains(8)); //false (No exception just warning when we use contains() for different data type)
System.out.println(al.indexOf("Sumit")); //1 first occurrence of "Sumit"
System.out.println(al.indexOf("sumit")); //-1
System.out.println(al.lastIndexOf("S"));//-1
//Reading from arrayList
System.out.println(al.get(0)); //first
/*
System.out.println(al.get(-1)); //Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
System.out.println(al.get(5)); //Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 5, Size: 3
*/
System.out.println(al.size()); //3
// System.out.println(al.remove(5)); //Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 5, Size: 3
System.out.println(al.remove(2)); //returns value at specified index or throws exception
System.out.println(al.size()); // 2
System.out.println(al); //[first, Sumit]
System.out.println(al.add("latest"));
System.out.println(al); //[first, Sumit, latest]
System.out.println((al.set(2, "sagar"))); // "Latest" returns old value at that index
System.out.println(al); //[first, Sumit, sagar]
// Looping######################################################33
for(int i=0;i<al.size();i++) {
System.out.println(al.get(i));
//first
//Sumit
//sagar
}
for(String s:al) {
System.out.println(s);
//first
//Sumit
//sagar }
// al.forEach((a)->System.out.println(a));
ArrayList<String> al2=new ArrayList<String>();
al2=al;
System.out.println(al2.equals(al)); //true
ArrayList<String> al3=new ArrayList<String>();
System.out.println(al3.equals(al)); //false
}
}
}
Rest Assured Chectsheet
REST Assured Cheat Sheet 🚀 REST Assured Cheat Sheet Complete Reference for ...
-
Description Waits until the specified object property achieves the specified value or exceeds the specified timeout ...
-
Suppose there is thread in a forum and we wish to navigate all pages of the forum. Below code can be useful Thread url: http://www.indi...
-
QTP AOM Script : Launch QTP, Create new test and Save it =============================================== dim qtpapp set qtpapp=create...