selenium page object & Page Factory
2015-11-30 21:20
260 查看
package demo; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; public class HomePage { public String base_url = "https://www.baidu.com/"; public WebDriver driver; WebElement inputBox; WebElement searchButton; /** * @author Young * @param message */ public void typeInputBox(String message) { inputBox = driver.findElement(By.id("kw")); inputBox.clear(); inputBox.sendKeys(message); } /** * @author Young */ public void clickSearchButton() { searchButton = driver.findElement((By.cssSelector("input#su"))); searchButton.click(); driver.manage().timeouts().pageLoadTimeout(90, TimeUnit.SECONDS); } /** * @author Young * @param d */ HomePage(WebDriver d) { this.driver = d; driver.get(base_url); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(90, TimeUnit.SECONDS); driver.manage().timeouts().pageLoadTimeout(90, TimeUnit.SECONDS); } /** * @author Young * @return */ public String getTitle() { return driver.getTitle(); } }
Page factory:
package demo; import java.util.concurrent.TimeUnit; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.How; import org.openqa.selenium.support.PageFactory; import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory; public class HomePage { public String base_url = "https://www.baidu.com/"; public WebDriver driver; @FindBy(how = How.ID, using = "kw") WebElement inputBox; @FindBy(how = How.CSS, using = "input#su") WebElement searchButton; /** * @author Young * @param message */ public void typeInputBox(String message) { inputBox.clear(); inputBox.sendKeys(message); } /** * @author Young */ public void clickSearchButton() { searchButton.click(); driver.manage().timeouts().pageLoadTimeout(90, TimeUnit.SECONDS); } /** * @author Young * @param d */ HomePage(WebDriver d) { this.driver = d; driver.get(base_url); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(90, TimeUnit.SECONDS); driver.manage().timeouts().pageLoadTimeout(90, TimeUnit.SECONDS); PageFactory.initElements(new AjaxElementLocatorFactory(driver, 15), this); } /** * @author Young * @return */ public String getTitle() { return driver.getTitle(); } }
相关文章推荐
- 懒加载的动态数组添加object需要self. 不能使用_
- 黑马程序员——Objective-C面向对象self和super关键词的用法笔记和举例
- 初识Objective-C
- 【Objective_C学习笔记】Block的使用
- Object类学习笔记
- [Objective-C]关联(objc_setAssociatedObject、objc_getAssociatedObject、objc_removeAssociatedObjects)
- C++中的临时对象temporary object
- [转]JSONObject与JSONArray的使用
- No package 'gobject-introspection-1.0' found
- ObjectInputStream和ObjectOutputStream
- net.sf.json.JSONArray & net.sf.json.JSONObject
- [Objective-C]__bridge,__bridge_retained和__bridge_t
- OC桥接转换
- AutoCAD2008+objectARX二次开发
- IOS 开发 【objective-c 基础1】
- PS: DeepProposal: Hunting Objects by Cascading Deep Convolutional Layers__ICCV2015
- PS:mproving Object Detection With Deep Convolutional Networks via Bayesian Optimization..___CVPR2015
- Objective-C NSData与实现NSCoding协议进行序列化和反序列化
- 十分钟让你明白Objective-C的语法(和Java、C++的对比)
- PS:Hypercolumns for Object Segmentation and Fine-Grained Localization__CVPR2015