package com.ahchoo.automation.page;
importorg.openqa.selenium.By;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.WebElement;
public class BaiduIndexPage {
privateWebDriver driver;
privatefinal String url = "http://www.baidu.com";
publicBaiduIndexPage(WebDriverdriver) {
this.driver=driver;
driver.get(url);
}
publicSearchResultPage searchFor(String term) {
// Baidusearch input id is "kw"
WebElement searchField = driver.findElement(By.id("kw"));
searchField.clear();
searchField.sendKeys(term);
searchField.submit();
returnnew SearchResultPage(driver);
}
}
package com.ahchoo.automation.page;
importorg.openqa.selenium.WebDriver;
public class SearchResultPage {
privateWebDriver driver;
publicSearchResultPage(WebDriver driver) {
this.driver=driver;
}
public StringgetTitle() {
returndriver.getTitle();
}
publicString getContent() {
returndriver.getPageSource();
}
}
package com.ahchoo.automation;
importstatic org.junit.Assert.*;
importorg.junit.After;
importorg.junit.Before;
importorg.junit.Test;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.firefox.FirefoxDriver;
importcom.ahchoo.automation.page.BaiduIndexPage;
importcom.ahchoo.automation.page.SearchResultPage;
public class SearchTest {
privateWebDriver driver;
@Before
public voidsetUp() {
driver = newFirefoxDriver();
}
@After
public voidtearDown() {
driver.close();
}
@Test
public voidsearchTest() {
BaiduIndexPage home = new BaiduIndexPage(driver);
SearchResultPage searchResult = home.searchFor("pizza");
assertTrue(searchResult.getTitle().contains("pizza"));
assertTrue(searchResult.getContent().contains("pizza"));
}
}
f
package com.ahchoo.automation.page;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.WebElement;
importorg.openqa.selenium.support.FindBy;
importorg.openqa.selenium.support.How;
public class BaiduIndexPage {
privateWebDriver driver;
privatefinal String url = "http://www.baidu.com";
publicBaiduIndexPage(WebDriverdriver) {
this.driver=driver;
driver.get(url);
}
@FindBy(how = How.ID, using="kw")
privateWebElement searchField;
publicSearchResultPage searchFor(String text) {
// Wecontinue using the element just as before
searchField.sendKeys(text);
searchField.submit();
returnnew SearchResultPage(driver);
}
}
相关推荐
WebDriver(PageObject模型-Python版).pdf
python 重新使用一个Webdriver的解决方法(csdn)————程序
Design effective automation frameworks using the PageObject pattern Learn how to deal with the latest features of WebDriver About the Author Satya Avasarala has rich experience in Java development...
WebDriver人工厂模式
webdriver API中文版 webdriver API中文版 2 1.1 下载selenium2.0的lib包 2 1.2 用webdriver打开一个浏览器 2 1.3 打开测试页面 3 1.4 GettingStarted 3 第2章 Webdirver对浏览器的支持 5 2.1 HtmlUnit Driver...
Selenium WebDriver + ReportNG 中文乱码问题解决方案。
页面对象 一个简单的gem,可帮助创建灵活的页面对象以测试基于浏览器的应用程序。 目的是促进在测试中创建抽象...您可以通过包含PageObject模块来定义新的页面对象: class LoginPage include PageObject end 当您
本书是一本从入门到精通模式的Selenium WebDriver实战经验分享书籍。全书共分为四个部分:第1部分基础篇主要讲解自动化测试相关的基础理论、WebDriver 环境安装、单元测试工具的使用方法以及 WebDrvier的入门使用...
Book Description Selenium WebDriver is an open source automation tool implemented ...The PageObject Pattern Mobile Testing on iOS and Android using Appium Data Driven Testing with TestNG Assessments
WebDriver实验版VB6版WebDriver实验,压缩包中有技术文档《WebDriver原理及实验》
webdriver-helper安装包,whl版本
Selenium-Webdriver系列教程 Selenium 1.x时代已经远去,它理应躺在历史的角落里,靠着壁炉烤着火,抽着旱烟,在袅袅的升起的青烟中回忆那曾经属于自己的美好时代。 不过事实却并非如此,现今原本早应退役的...
IE Webdriver Python
:warning:Scala + Spring + Hibernate + Maven + Selenium WebDriver 该项目包含使用Scala,Spring,Hibernate和Maven的最新版本启动Webapp项目的源代码,包括基于Selenium WebDriver PageObject的Web测试。...
webdriver安装包
php-webdriver-bindings这个PHP库允许创建功能测试与PHP webdriver
Selenium WebDriver详解及事例
VB6版WebDriver实验,压缩包中有技术文档《WebDriver原理及实验》《WebDriver命令编程手册(英文版、中文机翻版)》,代码演示的功能有:操作浏览器自动打开百度、搜索mp3,获得网页源码,获得网页标题,网页截图,...
webdriver 数据驱动 webdriver 数据驱动webdriver 数据驱动webdriver 数据驱动webdriver 数据驱动webdriver 数据驱动
ruby2.0.0+selenium-webdriver+watir-webdriver+rails离线备份,设置环境变量后可使用(未测试)