Java two-time selenium of the installation

Source: Internet
Author: User
Tags testng

Code Structure

Can be viewed on GitHub

Com.zlshuo.selenium.nonaming.driver: Generate the appropriate driver for each browser

Com.zlshuo.selenium.nonaming.driverinstance: Get Driverinstance instance
Com.zlshuo.selenium.nonaming.element: Get elements based on locator

Com.zlshuo.selenium.nonaming.operation: Browser, elements and other methods of operation and assertions
Com.zlshuo.selenium.nonaming.test: Test Trial
Com.zlshuo.selenium.nonaming.tools: Some tool classes

Class diagram

Draw the comparison stamp, will see it

Required JAR Packages

Related configuration

Since the original TESTNG test report was replaced with reportng, the following configuration is required in eclipse:

1.window->preferences->testng

2. Create a new Testng.xml and write the following:

<! DOCTYPE Suite SYSTEM "Http://testng.org/testng-1.0.dtd" > <suite name= "Testall" > <listeners> <list Ener class-name= "Org.uncommons.reportng.HTMLReporter"/> </listeners> <test name= "Order" > <c lasses> <class name= "Com.zlshuo.selenium.nonaming.test.Try"/> </classes> </test> ;</suite>

example code                                        &NBSP;&NBS P                          ,         &NB Sp                                                                   &NB sp;                     
Package com.zlshuo.selenium.nonaming.test; import org.testng.annotations.aftermethod;import  org.testng.annotations.BeforeMethod;import org.testng.annotations.Test; import  com.zlshuo.selenium.nonaming.driverinstance.createdriverinstance;import  com.zlshuo.selenium.nonaming.driverinstance.driverinstance;  public class try {         private DriverInstance driver=null;          @BeforeMethod     public void setup () {         //Generate Chrome's driverinstance         Driver=createdriverinstance.getdriverinstance ("Chrome");    }         //whether the search function is performed correctly      @Test     public void  test1 ()  throws interruptedexception{   &nbsP;            driver.get ("http://www.baidu.com");         driver.submit ("id$kw", "Search Selenium", ten, "Selenium");         driver.assertcontains ("Selenium",  driver.gettitle (),  " Determine if the title contains Selenium ");         thread.sleep (+);     }        //Search Selenium Click the first result and determine if title equals expected value       @Test     public void test2 ()  throws InterruptedException{                 driver.get ("HTTP/ Www.baidu.com ");         driver.submit (" id$kw "," Search Selenium ", 10," Selenium ")         driver.click ("//div[@id = ' 1 ']/h3/a[1] ");         d River.switchtowindow (2);         driver.assertequals ("Selenium -  web browser automation ",  driver.gettitle (), " title equals expected ");         thread.sleep (;    }       )   @AfterMethod     public void quit () {         driver.quit ();     }}

Java two selenium of a single

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.