利用模拟点击的方式进行集成测试,我们准备用google,Firefox和ie三种浏览器测试.
其中除了Firefox是模拟点击的鼻祖不需要插件外,谷歌和ie需要另外下载插件
chromedriver.exe;
IEDriverServer.exe
chrome测试:
File file = new File("C:/Selenium/chromeDriver.exe"); System.setProperty("webdriver.chrome.driver", file.getAbsolutePath()); driver = new ChromeDriver(); baseUrl = "http://www.cnblogs.com/"; driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); driver.get(baseUrl + "/garfieldcgf/"); driver.findElement( By.id("homepage1_HomePageDays_DaysList_ctl00_DayList_TitleUrl_0")) .click();
ie测试:
DesiredCapabilities caps = DesiredCapabilities.internetExplorer(); caps.setCapability( InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); File file = new File("C:/Selenium/IEDriverServer.exe"); System.setProperty("webdriver.ie.driver", file.getAbsolutePath()); driver = new InternetExplorerDriver(); baseUrl = "http://www.cnblogs.com/"; driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); driver.get(baseUrl + "/garfieldcgf/"); driver.findElement( By.id("homepage1_HomePageDays_DaysList_ctl00_DayList_TitleUrl_0")) .click();
Firefox测试:
driver = new FirefoxDriver(); baseUrl = "http://www.cnblogs.com/"; driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); driver.get(baseUrl + "/garfieldcgf/"); driver.findElement( By.id("homepage1_HomePageDays_DaysList_ctl00_DayList_TitleUrl_0")) .click();