VI – Automation Testing Frameworks Tool Installation and some hands-on examples
VI – Automation Testing Frameworks Tool Installation and some hands-on examples
DevOps

VI – Automation Testing Frameworks Tool Installation and some hands-on examples

Selenium

It is a popular open-source web-based automation tool. In this tutorial,we will learn how to install Selenium Webdriver.

Steps to be followed:
  • Download and setup Selenium server
  • Downloading ChromeDriver
  • Integrating selenium to Eclipse

Step 1: Download and setup Selenium server

  • Locate selenium using

    locate selenium

    command. If it is not present, then use the following command to update the packages.

    sudo apt-get update

    Download and setup Selenium server

  • Install selenium using below command:

    sudo pip install selenium

    Download and setup Selenium server

Step 2: Downloading ChromeDriver

  • Download the most preferable version. To execute the same, find out the Google chrome version available in your system. Open Google Chrome >> Click on three dots >> Help >> About Google Chrome.

    Downloading ChromeDriver

  • Now you can see the Google Chrome Version.

    Downloading ChromeDriver

  • Go to ChromeDriver downloads and select the version as shown below.

    Downloading ChromeDriver

  • You will be redirected to the page shown below. Select for Linux zip file.

    Downloading ChromeDriver

  • Now find the downloaded file in your system. For that you must extract the zip file. Ensure to copy the path and keep it for use.

    Downloading ChromeDriver

Step 3: Integrating Selenium to Eclipse

  • From your desktop, open the eclipse. Develop a new Java project in Eclipse. Right click on the project and make a new package. Once it is created, build a new class inside the package.
  • Further, configure the build path just by doing a right click on the developed project as shown below.

    Integrating Selenium to Eclipse

  • Click on Add external jar files for Selenium as shown below. The pop-up window will appear and will ask to select a file. Choose the Selenium jar file in the downloads section.

    Integrating Selenium to Eclipse

  • Click on Apply and Close.
  • You can see the referenced jar files as shown below.

    Integrating Selenium to Eclipse

Let’s have a look at hands-on Demo (Selenium – Test Case)

A test case is written for logging into yahoo.com.

  • Create a one
    first.java

    file to setup the selenium server jar file. Then we create a web driver instance for the same. And finally, we use

    driver.get()

    navigating to the respective URL and passing the username for the same.

  • Write the following code in the first.java file.

    package test;
    import java.util.concurrent.TimeUnit;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
        public class first {
            public static void main(String[] args) throws InterruptedException {
            System.setProperty(“webdriver.chrome.driver”, “/Path_To_Your_Chrome_Driver”);
            WebDriver driver = new ChromeDriver();
            driver.manage().window().maximize();
            driver.manage().deleteAllCookies();
            driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
            driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
            driver.get(“https://login.yahoo.com”);
            driver.findElement(By.xpath(“//input[@id=’login-username’]”)).sendKeys(“[email protected]”);
        }
    }
    
  • Right click on the written code and select Run As -> Java Application.
  • On executing the test case, you can see the output as shown below.

    Let’s have a look at hands-on Demo
    Let’s have a look at hands-on Demo

TestNG

Steps to be followed:
  • Download and set up TestNG
  • Integrate TestNG in Eclipse

Step 1: Downloading and set up TestNG

  • Open the terminal and type the command given below to download the TestNG.
    wget http://www.java2s.com/Code/JarDownload/testng/testng-6.8.7.jar.zip
  • Unzip the TestNG jar file using the command given below:

    unzip tes tng-6.8.7.jar.zip
  • You can see the testng same as selenium server in the downloads section.

    Downloading and set up TestNG

Step 2: Integrating TestNG in Eclipse

  • Go to the project in eclipse, right click on the project, select Build Path, and select Configure Build Path. Select Libraries and click on Add External JARs…. Browse and select the TestNG jar file. Refer to Lesson 6 Demo 1 to know how to configure the build path.

    Integrating TestNG in Eclipse

  • Click on Apply and Close.
  • You can see the referenced jar files for Testng as shown in the image below.

    Integrating TestNG in Eclipse

  • Go to the Help tab in the Eclipse and choose Eclipse Marketplace to configure TestNg.

    Integrating TestNG in Eclipse

  • Type TestNg in the find bar and click on Install. Select TestNG for Eclipse as shown in the below screenshot.

    Integrating TestNG in Eclipse

  • Once the installation is done, click on Confirm.
  • Select the checkbox I accept the terms of the license agreement and click on Finish.

A Glimpse into the Hands-on-Demo (TestNG – Test Case)

So, this is the place where we began to write the test case that the web page title should be the “Google”. Otherwise it failed the test case.

Testing the automation script
  • Open Eclipse, select the project, right click and select New-> Class. And provide the required information.
  • Copy the below code and paste it into the created class to write the TestNg test case. Do provide your own path for your chrome driver.
    package test;
    import org.testng.annotations.Test;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.testng.Assert;
    import org.testng.annotations.AfterTest;
    import org.testng.annotations.BeforeTest;
        
    public class testngfirst
    {
        public String baseUrl = "https://www.google.com/";
        String driverPath = "Path_To_Your_Chrome_Driver";
        public WebDriver driver ;
        
        @BeforeTest
        public void launchBrowser() 
        {
            System.out.println("launching Chrome browser");
            System.setProperty("webdriver.chrome.driver", driverPath);
            driver = new ChromeDriver();
            driver.get(baseUrl);
        }
        
        @Test
        public void verifyHomepageTitle() 
        {
            String expectedTitle = "Google";
            String actualTitle = driver.getTitle();
            Assert.assertEquals(actualTitle, expectedTitle);
        }
        
        @AfterTest
        public void terminateBrowser(){
            driver.close();
        }
    }
    
  • Right click on the written code. Select Run As -> TestNG Test. On executing the above on TestNG Test, you will get the following output.

    Testing the automation script
    Testing the automation script

STAY TUNE

DevOps Series – VII

Configuration Management (CM)

with Ansible

Nitin Suvagiya

Nitin Suvagiya

He is working with Softqube Technologies as Director, since 2009. He has over 15+ years of experience in Microsoft Technologies, working as a CEO and also providing consultation in DevOps as he is DevOps certified. He has good expertise in UX/UI designing in any application.