Friday 18 September 2015

TestNG + Selenium WebDriver configuration and execution


Install TestNG
1.        Launch the Eclipse IDE
2.       Navigate to Help->Install new software
3.       In Install dialog window, click “Add” button.
4.       Type name as you wish, for example :- “TestNG
5.       Type “http://beust.com/eclipse/” as location.
6.       Click OK.
7.        Just Click TestNG checkbox
8.       Press “Next” button.
9.       Click “I accept the terms of the license agreement
10.   Click Finish.
11.   Restart Eclipse

Create testng Class
1.       Right click on your package ( for this example package is p1)
2.       Select New-> Others->testing class
3.       Enter name of the class ( for this example name is testng1)
4.       Click OK
5.       Copy paste below code in the opened class

package p1;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.Assert;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class testng1 {
      
       WebDriver driver;
      
  @Test(groups = {"Regression"},priority = 2)
  @Parameters({"Browser1","url1"})
  public void test1(String sBrowser,String url) {
        
         if (sBrowser.equalsIgnoreCase("firefox"))
         {
                driver=new FirefoxDriver();
         }
         else if (sBrowser.equalsIgnoreCase("ie"))
         {
                System.setProperty("webdriver.ie.driver", "C:/imp/software/IEDriverServer.exe");
                driver=new InternetExplorerDriver();
         }
        
         else
         {
                System.out.println("Invalid browser");
                System.exit(0);
         }
        
         driver.get(url);
         String sTitle=driver.getTitle();
         System.out.println("Title is "+ sTitle);
         Assert.assertEquals("idojfioe", sTitle);
         driver.close();
  }
 
  @Test(groups = {"Smoketest"},priority = 1)
  @Parameters({"Browser2","url2"})
  public void test2(String sBrowser,String url) {
        
         if (sBrowser.equalsIgnoreCase("firefox"))
         {
                driver=new FirefoxDriver();
         }
         else if (sBrowser.equalsIgnoreCase("ie"))
         {
                System.setProperty("webdriver.ie.driver", "C:/imp/software/IEDriverServer.exe");
                driver=new InternetExplorerDriver();
         }
        
         else
         {
                System.out.println("Invalid browser");
                System.exit(0);
         }
        
         driver.get(url);
         String sTitle=driver.getTitle();
         System.out.println("Title is "+ sTitle);
         driver.close();
  }
}

Create TestNG xml file
1.       Right click on your Project
2.       Select New-> File
3.       Enter name of the file ( for this example name is testing.xml)
4.       Click OK
5.       Copy paste below code in xml file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="Suite" parallel="false">
                <parameter name="Browser1" value="firefox"/>
                <parameter name="Browser2" value="ie" />
                <parameter name="url1" value="http://www.google.com"/>
                <parameter name="url2" value="http://newtours.demoaut.com" />
                <test name="Selenium-AutomationSuite">
                                <groups>
                                                <run>
                                                                  <include name="Smoketest" />
                                  <include name="Regression" />
                                                </run>
                                </groups>
                                <classes>
                                                 <class name="p1.testng1"/>
                                                 
                                                 
                                               
                                </classes>
                </test>
</suite>

Run the Suite
1.       Right click on xml file(testing.xml)
2.       Navigate to Run as-> TestNG Suite



35 comments:

  1. Thanks for sharing this Information, Got to learn new things from your Blog on SELENIUM.
    Ref link : http://thecreatingexperts.com/software-testing-training-in-chennai/selenium-training-in- chennai/

    ReplyDelete
  2. Thanks for sharing this Information, Got to learn new things from your Blog on SELENIUM.
    Ref link :
    http://thecreatingexperts.com/software-testing-training-in-chennai/selenium-training-in-chennai/

    ReplyDelete
  3. Thanks for sharing this Information, Got to learn new things from your Blog on Megento.
    Ref link : http://thecreatingexperts.com/magento-training-in-chennai/

    ReplyDelete
  4. Thanks for sharing this information.It was very nice blog to learn about Selenium.
    http://thecreatingexperts.com/software-testing-training-in-chennai/selenium-training-in-chennai/

    ReplyDelete
  5. Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about Selenium.
    http://thecreatingexperts.com/software-testing-training-in-chennai/selenium-training-in-chennai/

    ReplyDelete

  6. A nice article here with some useful tips for those who are not used-to comment that frequently. Thanks for this helpful information I agree with all points you have given to us. I will follow all of them.

    Selenium Training in Chennai

    ReplyDelete
  7. This is very informative blog and article thank you for sharing with us keep posting more information about salesforce trainingselenium training, selenium online training, selenium course,learn selenium course

    ReplyDelete
  8. https://seleniumshiv.blogspot.in/2015/09/testng-selenium-webdriver-configuration.html

    ReplyDelete
  9. Thanks for sharing great information in your blog.

    Selenium training institute which provides Real Time Hands on Training…THE CREATING EXPERTS

    http://thecreatingexperts.com/selenium-training-in-chennai/


    contact-8122241286

    ReplyDelete
  10. Excellent Article ...thank u for sharing, such a valuable content Learners to get good knowledge after read this article.. Selenium Training in Chennai | Selenium Training in Chennai

    ReplyDelete
  11. Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information.
    PHP Training in Chennai
    PHP Institutes in Chennai
    PHP courses in chennai
    PHP Training Chennai
    PHP Course Chennai

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete
  13. Nice post. I learned some new information. Thanks for sharing.

    Guest posting sites
    Education

    ReplyDelete
  14. The blog is well written. Thanks for your information.Java is fast, secure and reliable platform. there are lots of application and websites works under java and it is platform independant
    Best Institute for JAVA
    Best JAVA Training
    JAVA Programming Certification Course
    Best JAVA Certification
    Best JAVA Training

    ReplyDelete