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

package collectionInterface;
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

package collectionInterface;
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


   
   
   
    }
}
}

Thursday, 18 July 2019

UFT:'ReadParameter_FN

'@Description This function reads the action parameter value and returns back.
'@Documentation This function reads the action parameter value and returns back.
Function ReadParameter_FN(str_Name)

Err.Clear
Dim tempValue
tempValue = str_Name
On Error Resume Next

dataSource = "Global"
ReadParameter_FN = Datatable.Value(str_Name,dataSource)

If Err.Number <> 0 Then
Err.Clear
dataSource = Environment.Value("ActionName")
If Environment.Value("localRowIndex") = 0 Then
Environment.Value("localRowIndex") = 1
End If
datatable.LocalSheet.SetCurrentRow Environment.Value("localRowIndex")
ReadParameter_FN = Datatable.Value(str_Name,dataSource)
End If


If Err.Number <> 0 Then
Call ReportEvent_FN("Fail", "Read Value from Datasheet", "Reading parameter : "&str_Name&" from Datasheet is failed. Description:"&Err.Description)
End If

Err.Clear

End Function

UFT: WriteParameter_FN

'@Description This function writes the action parameter value and returns back.
'@Documentation This function writes the action parameter value and returns back.
Function WriteParameter_FN(str_Name, str_Value)

Err.Clear
     On Error Resume Next
Datatable.Value(str_Name,dataSource) = str_Value

If Err.Number <> 0 Then
DataTable.getSheet(dataSource).AddParameter str_Name, str_Value
Err.Clear
End If

If dataSource <> "Global" Then
Datatable.Value(str_Name,"Global") = str_Value
If Err.Number <> 0 Then
DataTable.getSheet("Global").AddParameter str_Name, str_Value
Err.Clear
End If
End If
Err.Clear

End Function

UFT ValidateRegularPattern_FN function

Function ValidateRegularPattern_FN(str_Pattern, str_Value)
Err.Clear

Dim regEx, Match

Set regEx = New RegExp   ' Create a regular expression.
regEx.Pattern = str_Pattern   ' Set pattern.
regEx.IgnoreCase = True   ' Set case insensitivity.
regEx.Global = True   ' Set global applicability.
Match  = regEx.Test(str_Value)   ' Execute search.
 
ValidateRegularPattern_FN = Match

Err.Clear

End Function

Rest Assured Chectsheet

REST Assured Cheat Sheet 🚀 REST Assured Cheat Sheet Complete Reference for ...