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