标签:
可以到github上查看
com.zlshuo.selenium.nonaming.driver:生成各浏览器相应的driver
com.zlshuo.selenium.nonaming.driverinstance:获取driverinstance实例
com.zlshuo.selenium.nonaming.element:根据定位器获取元素
com.zlshuo.selenium.nonaming.operation:浏览器、元素等操作方法及断言
com.zlshuo.selenium.nonaming.test:测试用
com.zlshuo.selenium.nonaming.tools:一些工具类
画的比较戳,将就看吧
由于用reportng代替了原来testng的测试报告,故需要在eclipse中做如下配置:
1.Window->preferences->TestNG
2.新建testng.xml,写入如下内容
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite name="TestAll"> <listeners> <listener class-name="org.uncommons.reportng.HTMLReporter"/> </listeners> <test name="order"> <classes> <class name="com.zlshuo.selenium.nonaming.test.Try" /> </classes> </test> </suite>
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(){ //生成chrome的driverInstance driver=CreateDriverInstance.getDriverInstance("chrome"); } //是否正确执行搜索功能 @Test public void test1() throws InterruptedException{ driver.get("http://www.baidu.com"); driver.submit("id$kw","搜索selenium",10,"selenium"); driver.assertContains("selenium", driver.getTitle(), "判断title中是否含有selenium"); Thread.sleep(3000); } //搜索selenium点击第一条结果并判断title是否等于预期值 @Test public void test2() throws InterruptedException{ driver.get("http://www.baidu.com"); driver.submit("id$kw","搜索selenium",10,"selenium"); driver.click("//div[@id=‘1‘]/h3/a[1]"); driver.switchToWindow(2); driver.assertEquals("Selenium - Web Browser Automation", driver.getTitle(), "title是否等于预期"); Thread.sleep(3000); } @AfterMethod public void quit(){ driver.quit(); } }
标签:
原文地址:http://my.oschina.net/u/2299197/blog/363841