Friday, January 31, 2020

Rouff

Wait types?
thread
webdriver wait
fuent wait

where to use implicit? where to use explicit?


javascipt executor for send ket text.

id is not present then javascript executor work mor not?


how to click without click method?
ans:  .submit()

how to stop TC for some seconds?

dr.get ? dr.nevigate() diff?

[20:57, 1/31/2020] Rahul Bhujbal: Api driver
Headless mode html why fast
Grid in selenium
Open source testing cucumber
Xpath by axes
Which locator foster
Single slash and double slash in xpath
Assert and verify
Soft assert and hard assert
[20:57, 1/31/2020] Rahul Bhujbal: Maven life cycle

PO package
          Class1. Java
           Class2. Java

Cmd promt
Mvn validate
Mvn compile
Mvn test
Mvn package

Mvn h test

Mvn Package - it create jar or var file or create executable file.

Validation
Compile
Test
[20:59, 1/31/2020] Rahul Bhujbal: Hashmap
Hashtable
Linklisat
Arrrayliay
Io check except
Still element exception
Find element
Fine elements
Get window badle
Hash map returns key
Cucumber scenario how to work
Restasure explain work
Post call program
Put header set?
Method id and Overriding  diff.
Payment gateway credit card.
Cross browser testing

Why maven?
Build tool


Steal element

Why we are adding Dependency?
Tolerance
String builder and string buffer

Regular expressions in cucumbercucumbe

Tell about Framwork?
Cucber
Pom
Log 4j

We can write so many Scenarios in single feature file.
Yes but we can't write it
Not Advicible

Baground keyword
Hooks in cucumber

We can use tag for ring before after once in cucumber

Surefire and fail use for parallel execution

http://www.automationfraternity.com/selenium/how-to-explain-current-project-and-fw-structure/

Maven - Life Cycle

What is Build Lifecycle?

A Build Lifecycle is a well-defined sequence of phases, which define the order in which the goals are to be executed. Here phase represents a stage in life cycle. As an example, a typical Maven Build Lifecycle consists of the following sequence of phases.
PhaseHandlesDescription
prepare-resourcesresource copyingResource copying can be customized in this phase.
validateValidating the informationValidates if the project is correct and if all necessary information is available.
compilecompilationSource code compilation is done in this phase.
TestTestingTests the compiled source code suitable for testing framework.
packagepackagingThis phase creates the JAR/WAR package as mentioned in the packaging in POM.xml.
installinstallationThis phase installs the package in local/remote maven repository.
DeployDeployingCopies the final package to the remote repository.




- Testing the same piece of software, we can't be unfair to test it with just one set of data.
- we need to verify that our system is taking all set of combinations which it expected to support.
- So comes Parameterization in the picture.
- To pass multiple data to the application at runtime, we need to parameterize our test scripts.
- This concept which we achieve by parameterization is called Data Driven Testing.

We will go through the parameterization options in Selenium Webdriver - TestNG.

There are two ways by which we can achieve parameterization in TestNG

With the help of Parameters annotation and TestNG XML file.

  1. With the help of Parameters annotation and TestNG XML file.
    TestNG: Parameterization using XML & DataProvider in Selenium
  2. With the help of DataProvider annotation.
    TestNG: Parameterization using XML & DataProvider in Selenium
TestNG: Parameterization using XML & DataProvider in Selenium

Parameters from Testng.xml can be suite or test level
Parameter from DataProvider can take Method and ITestContext as the parameter.

Parameters annotation with Testng.xml

Select parameterization using annotations when you do want to deal with complexity & the number of input combinations are less.
Let see how this works
Test Scenario
Step 1) Launch browser & go to Google.com
Step 2) Enter a search keyword
TestNG: Parameterization using XML & DataProvider in Selenium
Step 3) Verify the inputted value is same as that provided by our test data
Step 4) Repeat 2 & 3 until all values are inputted

package parameters;

import org.testng.annotations.Test;
import org.testng.AssertJUnit;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class NoParameterWithTestNGXML {
 String driverPath = "C:\\geckodriver.exe";
 WebDriver driver;
    
    @Test
    public void testNoParameter() throws InterruptedException{
        String author = "guru99";
        String searchKey = "india";
        
        System.setProperty("webdriver.gecko.driver", driverPath);        
        driver= new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        
        driver.get("https://google.com");
        WebElement searchText = driver.findElement(By.name("q"));
        //Searching text in google text box
        searchText.sendKeys(searchKey);
        
        System.out.println("Welcome ->"+author+" Your search key is->"+searchKey);
                System.out.println("Thread will sleep now");
        
        Thread.sleep(3000);
        System.out.println("Value in Google Search Box = "+searchText.getAttribute("value") +" ::: Value given by input = "+searchKey);
        //verifying the value in google search box
        AssertJUnit.assertTrue(searchText.getAttribute("value").equalsIgnoreCase(searchKey));
}
}


Now, let's parameterize this using TestNG
To do so, you will need to
  • Create an XML file which will store the parameters
  • In the test, add annotation @Parameters
TestNG: Parameterization using XML & DataProvider in Selenium
Here is the complete code
Test Level TestNG.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="TestSuite" thread-count="3" >
<parameter name="author" value="Guru99" />
<parameter name="searchKey" value="India" />
<test name="testGuru">
<parameter name="searchKey" value="UK" />
<classes>
<class name="parameters.ParameterWithTestNGXML">
</class>
</classes>
</test>
</suite>
ParameterWithTestNGXML.java File
package parameters;

import org.testng.AssertJUnit;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class ParameterWithTestNGXML {
 String driverPath = "C:\\geckodriver.exe";
 WebDriver driver;
    @Test
    @Parameters({"author","searchKey"})
    public void testParameterWithXML( @Optional("Abc") String author,String searchKey) throws InterruptedException{

        System.setProperty("webdriver.gecko.driver", driverPath);
        driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.get("https://google.com");

        WebElement searchText = driver.findElement(By.name("q"));
        //Searching text in google text box
        searchText.sendKeys(searchKey);

        System.out.println("Welcome ->"+author+" Your search key is->"+searchKey);
        System.out.println("Thread will sleep now");
        Thread.sleep(3000);
        System.out.println("Value in Google Search Box = "+searchText.getAttribute("value") +" ::: Value given by input = "+searchKey);
        //verifying the value in google search box
        AssertJUnit.assertTrue(searchText.getAttribute("value").equalsIgnoreCase(searchKey));

}
}
Note: To run the script, select the XML file and Run as Test NG Suite.
Now, parameters can be defined at 2 levels
  1. Suite level – The parameters inside the <suite> tag of TestNG XML file will be a suite level parameter.
  2. Test Level -- The parameters inside the <Test> tag of testing XML file will be a Test level parameter.
Here is the same test with suite level parameters
TestNG: Parameterization using XML & DataProvider in Selenium

Parameters using Dataprovider

@Parameters annotation is easy but to test with multiple sets of data we need to use Data Provider.
To fill thousand's of web forms using our testing framework we need a different methodology which can give us a very large dataset in a single execution flow.
This data driven concept is achieved by @DataProvider annotation in TestNG.
TestNG: Parameterization using XML & DataProvider in Selenium
It has only one attribute 'name'. If you do not specify the name attribute then the DataProvider's name will be same as the corresponding method name.
Data provider returns a two-dimensional JAVA object to the test method and the test method, will invoke M times in a M*N type of object array. For example, if the DataProvider returns an array of 2*3 objects, the corresponding testcase will be invoked 2 times with 3 parameters each time.
TestNG: Parameterization using XML & DataProvider in Selenium
Complete Example
TestNG: Parameterization using XML & DataProvider in Selenium
package parameters;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

import org.testng.Assert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class ParameterByDataprovider {
    WebDriver driver;
    String driverPath = "C:\\geckodriver.exe";

    @BeforeTest
    public void setup(){
        //Create firefox driver object
         System.setProperty("webdriver.gecko.driver", driverPath);
         driver = new FirefoxDriver();
         driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
         driver.get("https://google.com");
    }
 
    /** Test case to verify google search box
     * @param author
     * @param searchKey
     * @throws InterruptedException
     */

    @Test(dataProvider="SearchProvider")
    public void testMethod(String author,String searchKey) throws InterruptedException{
    {
        WebElement searchText = driver.findElement(By.name("q"));
        //search value in google searchbox
        searchText.sendKeys(searchKey);
        System.out.println("Welcome ->"+author+" Your search key is->"+searchKey);
        Thread.sleep(3000);
        String testValue = searchText.getAttribute("value");
        System.out.println(testValue +"::::"+searchKey);
        searchText.clear();
        //Verify if the value in google search box is correct
        Assert.assertTrue(testValue.equalsIgnoreCase(searchKey));
    }
    }
    /**
     * @return Object[][] where first column contains 'author'
     * and second column contains 'searchKey'
     */

    @DataProvider(name="SearchProvider")
    public Object[][] getDataFromDataprovider(){
    return new Object[][] 
     {
            { "Guru99", "India" },
            { "Krishna", "UK" },
            { "Bhupesh", "USA" }
        };

    }

}

Invoke DataProvider from different class

By default, DataProvider resides in the same class where test method is or its base class. To put it in some other class we need to make data provider method as static and in test method we need to add an attribute dataProviderClass in @Test annotation.
TestNG: Parameterization using XML & DataProvider in Selenium
Code Example
TestNG: Parameterization using XML & DataProvider in Selenium

TestClass ParameterDataproviderWithClassLevel.java
package parameters;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class ParameterDataproviderWithClassLevel {
    WebDriver driver;
    String driverPath = "C:\\geckodriver.exe";
    
  @BeforeTest
    public void setup(){
   System.setProperty("webdriver.gecko.driver", driverPath);
  driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.get("https://google.com");
    }
   
    @Test(dataProvider="SearchProvider",dataProviderClass=DataproviderClass.class)
    public void testMethod(String author,String searchKey) throws InterruptedException{
        
        WebElement searchText = driver.findElement(By.name("q"));
        //Search text in google text box
        searchText.sendKeys(searchKey);
        System.out.println("Welcome ->"+author+" Your search key is->"+searchKey);
        Thread.sleep(3000);
        //get text from search box
        String testValue = searchText.getAttribute("value");
        System.out.println(testValue +"::::"+searchKey);
        searchText.clear();
        //verify if search box has correct value
        Assert.assertTrue(testValue.equalsIgnoreCase(searchKey));
   }
}
DataproviderClass.java
package parameters;

import org.testng.annotations.DataProvider;
public class DataproviderClass {
        @DataProvider(name="SearchProvider")
        public static Object[][] getDataFromDataprovider(){
            return new Object[][] {
                { "Guru99", "India" },
                { "Krishna", "UK" },
                { "Bhupesh", "USA" }
            };  
}}

Types of Parameters in Dataprovider

There are two type of parameters supported by DataProvider method.
Method- If the SAME DataProvider should behave differently with different test method , use Method parameter.
TestNG: Parameterization using XML & DataProvider in Selenium
In the following example ,
  • We check if method name is testMethodA.
  • If yes return one set of value
  • Else return another set of value
package parameters;

import java.lang.reflect.Method;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class ParameterByMethodInDataprovider{

    WebDriver driver;
    String driverPath = "C:\\geckodriver.exe";
     
    @BeforeTest
    public void setup(){
     System.setProperty("webdriver.gecko.driver", driverPath);
     driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.get("https://google.com");
    }

    @Test(dataProvider="SearchProvider")
    public void testMethodA(String author,String searchKey) throws InterruptedException{
        
     WebElement searchText = driver.findElement(By.name("q"));
        //Search text in search box
        searchText.sendKeys(searchKey);
        //Print author and search string
        System.out.println("Welcome ->"+author+" Your search key is->"+searchKey);
        Thread.sleep(3000);
        String testValue = searchText.getAttribute("value");
        System.out.println(testValue +"::::"+searchKey);
        searchText.clear();
        //Verify if google text box is showing correct value
        Assert.assertTrue(testValue.equalsIgnoreCase(searchKey));
    }
      
    @Test(dataProvider="SearchProvider")
    public void testMethodB(String searchKey) throws InterruptedException{
        {
         WebElement searchText = driver.findElement(By.name("q"));
            //Search text in search box
            searchText.sendKeys(searchKey);
            //Print only search string
            System.out.println("Welcome ->Unknown user Your search key is->"+searchKey);
            Thread.sleep(3000);
            String testValue = searchText.getAttribute("value");
            System.out.println(testValue +"::::"+searchKey);
            searchText.clear();
            //Verify if google text box is showing correct value
            Assert.assertTrue(testValue.equalsIgnoreCase(searchKey));
        }
    }    
    /**
     * Here DataProvider returning value on the basis of test method name
     * @param m
     * @return
     **/

    @DataProvider(name="SearchProvider")
    public Object[][] getDataFromDataprovider(Method m){
        if(m.getName().equalsIgnoreCase("testMethodA")){
        return new Object[][] {
                { "Guru99", "India" },
                { "Krishna", "UK" },
                { "Bhupesh", "USA" }
            };}
        else{
        return new Object[][] {
                { "Canada" },
                { "Russia" },
                { "Japan" }
            };}       
    }
}
Here is the output
TestNG: Parameterization using XML & DataProvider in Selenium
ITestContext- It can use to create different parameters for test cases based on groups.
In real-life, you can use ITestContext to vary parameter values based on Test Methods, hosts, configurations of the test.
TestNG: Parameterization using XML & DataProvider in Selenium
In the following code example
  • We have 2 groups A & B
  • Each test method is assigned to a group
  • If value of group is A, a particular data set is returned
  • If value of group is B, another data set is returned
package parameters;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.ITestContext;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class ParameterByITestContextInDataprovider {
 WebDriver driver;
 String driverPath = "C:\\geckodriver.exe";
 @BeforeTest(groups={"A","B"})
 public void setup(){
  System.setProperty("webdriver.gecko.driver", driverPath);
     driver = new FirefoxDriver();
   driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
   driver.get("https://google.com");
 }
 
 @Test(dataProvider="SearchProvider",groups="A")
 public void testMethodA(String author,String searchKey) throws InterruptedException{
  {
    //search google textbox
   WebElement searchText = driver.findElement(By.name("q"));
   //search a value on it
   searchText.sendKeys(searchKey);
   System.out.println("Welcome ->"+author+" Your search key is->"+searchKey);
   Thread.sleep(3000);
   String testValue = searchText.getAttribute("value");
   System.out.println(testValue +"::::"+searchKey);
   searchText.clear();
   //verify correct value in searchbox
   Assert.assertTrue(testValue.equalsIgnoreCase(searchKey));
 }
 }
 
 @Test(dataProvider="SearchProvider",groups="B")
 public void testMethodB(String searchKey) throws InterruptedException{
  {
    //find google search box
   WebElement searchText = driver.findElement(By.name("q"));
   //search a value on it
   searchText.sendKeys(searchKey);
   System.out.println("Welcome ->Unknown user Your search key is->"+searchKey);
   Thread.sleep(3000);
   String testValue = searchText.getAttribute("value");
   System.out.println(testValue +"::::"+searchKey);
   searchText.clear();
   //verify correct value in searchbox
   Assert.assertTrue(testValue.equalsIgnoreCase(searchKey));
 }
 }
 
 /**
  * Here the DAtaProvider will provide Object array on the basis on ITestContext
  * @param c
  * @return
  */
 @DataProvider(name="SearchProvider")
 public Object[][] getDataFromDataprovider(ITestContext c){
 Object[][] groupArray = null;
  for (String group : c.getIncludedGroups()) {
  if(group.equalsIgnoreCase("A")){
   groupArray = new Object[][] { 
     { "Guru99", "India" }, 
     { "Krishna", "UK" }, 
     { "Bhupesh", "USA" } 
    };
  break; 
  }
   else if(group.equalsIgnoreCase("B"))
   {
   groupArray = new Object[][] { 
      {  "Canada" }, 
      {  "Russia" }, 
      {  "Japan" } 
     };
   }
  break;
 }
 return groupArray;  
 }
}
Note: If you directly run your testng class, it will first call dataprovider which can't get groups information as groups are not available. But instead if you call this class via testng.xml, it will have groups info available with ITestContext. Use the following XML to call the test
<!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
<suite name="test-parameter">

  <test name="example1">

    <groups>
        <run>
            <include name="A" />
        </run>
    </groups>

    <classes>
       <class
        name="parameters.ParameterByITestContextInDataprovider" />
    </classes>

  </test>


  <test name="example2">

    <groups>
        <run>
            <include name="B" />
        </run>
    </groups>

    <classes>
       <class
        name="parameters.ParameterByITestContextInDataprovider" />
    </classes>

  </test>

</suite>
Summary:
  • Parameterization is require to create Data Driven Testing.
  • TestNG support two kinds of parameterization, using @Parameter+TestNG.xml and using@DataProvider
  • In @Parameter+TestNG.xml parameters can be placed in suite level and test level. If
    The Same parameter name is declared in both places; test level parameter will get preference over suit level parameter.
  • using @Parameter+TestNG.xml only one value can be set at a time, but @DataProvider return an 2d array of Object.
  • If DataProvider is present in the different class then the class where the test method resides,DataProvider should be static method.
  • There are two parameters supported by DataProvider are Method and ITestContext.


Monday, January 20, 2020

How to create Basic Selenium Project with Maven, TestNG and POM



File-> New-> Others->Select Maven Project from Maven Folder->Click Next->Tick on Create a Simple Project(Skip archetype Selection)

Group ID:com.TestAutomation
 Add Signature in Group ID

Artifact ID: TestAutomation


Open POM File:

  Add Properties
  <properties>
  <project.build.sourceEncoding>UFT-8</project.build.sourceEncoding>
  <maven.compiler.source>1.8</maven.compiler.source>
  <maven.compile.target>1.8</maven.compile.target>
  </properties>
 

  Add  Required Dependencies :

  <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.141.59</version>
  </dependency>
 

  <dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.14.3</version>
    <scope>test</scope>
</dependency>
<dependency>

Then Create Packages & Classes for Page Objects(PO) and TC (Test Cases)

POC - Proof of Concepts

Every E-Commerce site has two Front ends one is Store Front and second is Administration Panel

Webdriver driver =new Chromedriver();

Webdriver is an Interface

Relation between chromedriver and Webdriver is Chrome Driver is Implementing the Webdriver

After all POM done then Create a Runner.XML File src/test/respurces

POM is application page map with java class.

POM has different Approaches.
e.g 1. By using page Factory 

Thursday, January 16, 2020

TestNG Annotations

Annotation & Description

  • @BeforeMethod: A method with this annotation will be executed before every @test annotated method.
  • @AfterMethod: This annotation will be executed after every @test annotated method.
  • @BeforeClass: This annotation will be executed before first @Test method execution. It runs only once per class.
  • @AfterClass: This annotation will be executed after all the test methods in the current class have been run
  • @BeforeTest: A method with this annotation will be executed before first @Test annotated method.
  • @AfterTest: A method with this annotation will be executed when all @Test annotated methods complete the execution of those classes which are inside <test> tag in TestNG.xml file.
  • @BeforeSuite: This annotation will run only once before all tests in the suite have run
  • @AfterSuite: A method with this annotation will run once after the execution of all tests in the suite have run
  • @BeforeGroups: This annotated method will run before the first test run of that specific group.
  • @AfterGroups: This annotated method will run after all test methods of that group completes its execution.

@Test
This is the main part of our automation script where we will write the business logic, the things which we want to automate. We can pass attributes to our test method.
Below are the lists of attributes that we can pass to our Test method:
  • alwaysRun : This is used when we want to make sure a method always runs even if the parameters on which the method depends, fails. If set to true, this test method will always run. Eg: @Test(alwaysRun = true)
  • dataProvider: TestNG dataProvider is used to provide any data for parameterization. Eg. @Test(dataProvider = “Hello”).

E.g. 
public class SameClassDataProvider 
{
    @DataProvider(name = "data-provider")
    public Object[][] dataProviderMethod() {
        return new Object[][] { { "data one" }, { "data two" } };
    }
    @Test(dataProvider = "data-provider")
    public void testMethod(String data) {
        System.out.println("Data is: " + data);
    }
}
  • dataProviderClass: This is the class from where we pass the data to data provider. In our case dataProvider class name is “Hello”.

DataProvider.java


import org.testng.annotations.DataProvider;
public class DataProviderClass 
{
    @DataProvider(name = "data-provider")
    public static Object[][] dataProviderMethod() 
    {
        return new Object[][] { { "data one" }, { "data two" } };
    }
}
TestClass.java

import org.testng.annotations.Test;
public class TestClass 
{
    @Test(dataProvider = "data-provider", dataProviderClass = DataProviderClass.class)
    public void testMethod(String data) 
    {
        System.out.println("Data is: " + data);
    }
}
  • dependsOnGroups: It is the list of groups this method depends on. Eg: @Test (groups = { “City” ,”State” })
  • dependsOnMethods: This command is used to execute a method based on its dependent method. Eg: @Test (dependsOnMethods = { “OpenBrowser” ,”database is up” })
  • description: It is the description for the method. Eg: @Test(description = “test method”)
  • invocationCount: It refers to the number of times a method should be invoked. It will work as a loop. Eg: @Test(invocationCount = 7) . Hence, this method will execute 7 times.
  • invocationTimeOut: This refers to the maximum number of milliseconds a method should take for all the invocationCount to complete. This attribute will be ignored if invocationCount is not specified. Eg: @Test(invocationCount =7,invocationTimeOut = 30 )
  • priority: This command sets the priority of the test method. Lower priorities will be scheduled first. Eg: @Test(priority =1 )
import static org.testng.Assert.assertEquals; import java.io.File; import java.io.IOException; import java.util.concurrent.TimeUnit; import org.apache.commons.io.FileUtils; import org.openqa.selenium.By; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.annotations.AfterClass; import org.testng.annotations.AfterGroups; import org.testng.annotations.AfterMethod; import org.testng.annotations.AfterSuite; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeSuite; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; public class AnnotationsTestNG { public WebDriver driver; public String url="https://www.lambdatest.com/"; @BeforeSuite public void setUp() { System.setProperty("webdriver.chrome.driver", "C:\\Users\\navyug\\workspace\\QAPractise\\src\\ChromeDriver\\chromedriver.exe"); driver=new ChromeDriver(); driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); System.out.println("The setup process is completed"); } @BeforeTest public void profileSetup() { driver.manage().window().maximize(); System.out.println("The profile setup process is completed"); } @BeforeClass public void appSetup() { driver.get(url); System.out.println("The app setup process is completed"); } @BeforeMethod public void checkLogin() { driver.get("https://accounts.lambdatest.com/login"); driver.findElement(By.xpath("//input[@name='email']")).sendKeys("sadhvisingh24@gmail.com"); driver.findElement(By.xpath("//input[@name='password']")).sendKeys("activa9049"); driver.findElement(By.xpath("//*[@id='app']/section/form/div/div/button")).click(); System.out.println("The login process on lamdatest is completed"); } @Test(groups="urlValidation") public void testCurrentUrl() throws InterruptedException { driver.findElement(By.xpath("//*[@id='app']/header/aside/ul/li[4]/a")).click(); Thread.sleep(6000); String currentUrl= driver.getCurrentUrl(); assertEquals(currentUrl, "https://automation.lambdatest.com/timeline/?viewType=build&page=1", "url did not matched"); System.out.println("The url validation test is completed"); } @AfterMethod public void screenShot() throws IOException { TakesScreenshot scr= ((TakesScreenshot)driver); File file1= scr.getScreenshotAs(OutputType.FILE); FileUtils.copyFile(file1, new File("C:\\Users\\navyug\\workspace\\QAPractise\\test-output\\test1.PNG")); System.out.println("Screenshot of the test is taken"); } @AfterClass public void closeUp() { driver.close(); System.out.println("The close_up process is completed"); } @AfterTest public void reportReady() { System.out.println("Report is ready to be shared, with screenshots of tests"); } @AfterSuite public void cleanUp() { System.out.println("All close up activities completed"); } @BeforeGroups("urlValidation") public void setUpSecurity() { System.out.println("url validation test starting"); } @AfterGroups("urlValidation") public void tearDownSecurity() { System.out.println("url validation test finished"); } }

Wednesday, January 15, 2020

GIT Commands


Getting & Creating Projects

CommandDescription
git initInitialize a local Git repository
git clone ssh://git@github.com/[username]/[repository-name].gitCreate a local copy of a remote repository

Basic Snapshotting

CommandDescription
git statusCheck status
git add [file-name.txt]Add a file to the staging area
git add -AAdd all new and changed files to the staging area
git commit -m "[commit message]"Commit changes
git rm -r [file-name.txt]Remove a file (or folder)

Branching & Merging

CommandDescription
git branchList branches (the asterisk denotes the current branch)
git branch -aList all branches (local and remote)
git branch [branch name]Create a new branch
git branch -d [branch name]Delete a branch
git push origin --delete [branch name]Delete a remote branch
git checkout -b [branch name]Create a new branch and switch to it
git checkout -b [branch name] origin/[branch name]Clone a remote branch and switch to it
git branch -m [old branch name] [new branch name]Rename a local branch
git checkout [branch name]Switch to a branch
git checkout -Switch to the branch last checked out
git checkout -- [file-name.txt]Discard changes to a file
git merge [branch name]Merge a branch into the active branch
git merge [source branch] [target branch]Merge a branch into a target branch
git stashStash changes in a dirty working directory
git stash clearRemove all stashed entries

Sharing & Updating Projects

CommandDescription
git push origin [branch name]Push a branch to your remote repository
git push -u origin [branch name]Push changes to remote repository (and remember the branch)
git pushPush changes to remote repository (remembered branch)
git push origin --delete [branch name]Delete a remote branch
git pullUpdate local repository to the newest commit
git pull origin [branch name]Pull changes from remote repository
git remote add origin ssh://git@github.com/[username]/[repository-name].gitAdd a remote repository
git remote set-url origin ssh://git@github.com/[username]/[repository-name].gitSet a repository's origin branch to SSH

Inspection & Comparison

CommandDescription
git logView changes
git log --summaryView changes (detailed)
git log --onelineView changes (briefly)
git diff [source branch] [target branch]Preview changes before merging

Inspection & Comparison:

How to import Code from Master to your Branch and then on your machine & in your Eclipse:

1. Go to Master Branch which you want to import.

2. Create New Branch from Master Branch with Any Name e..g. RahulB_NewCucumber
3. Click on Clone and Download-> copy url from Clone with HTTP


4. Create one Folder where you want to store cloned project. e.g. C:\Users\CucumberProject

5. Open Git Bash cmd Prompt go to the path where we created Folder 
e.g. Administrator@Lenovo MINGW64 /c/Users/CucumberProject

6. Hit cmd
 git clone https://github.com/akashdktyagi/VisionIT_7.git


7. Now Project is Available on your Branch & Local Machine. Now open it on your Eclipse by Click on on File-> Open Project from File System->Select Directory -> Finish. Now we can see Project on Eclipse.


8. Now Every time we can write TCs & push it on your Branch.