Selenium PageObject实例
2014-12-17 16:44
253 查看
教你如何使用Selenium PageObject,已Baidu查询为例子.
1.编写BaiduSearchPage类.代码如下:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
public class BaiduSearchPage {
private WebDriver driver;
@FindBy(id="kw")
private WebElement searchValue;
@FindBy(id="su")
private WebElement btnButton;
public void searchValue(String seachConditon){
searchValue.sendKeys(seachConditon);
btnButton.click();
}
}
2.编写测试类
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.PageFactory;
public class TestPageObject {
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver = new FirefoxDriver();
driver.get("http://www.baidu.com/");
BaiduSearchPage page = PageFactory.initElements(driver, BaiduSearchPage.class);
page.searchValue("China");
}
}
1.编写BaiduSearchPage类.代码如下:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
public class BaiduSearchPage {
private WebDriver driver;
@FindBy(id="kw")
private WebElement searchValue;
@FindBy(id="su")
private WebElement btnButton;
public void searchValue(String seachConditon){
searchValue.sendKeys(seachConditon);
btnButton.click();
}
}
2.编写测试类
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.PageFactory;
public class TestPageObject {
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver = new FirefoxDriver();
driver.get("http://www.baidu.com/");
BaiduSearchPage page = PageFactory.initElements(driver, BaiduSearchPage.class);
page.searchValue("China");
}
}
相关文章推荐
- selenium系列->Actions命令实例整理->captrueEntirePageScr...
- Selenium的PageFactory & PageObject 在大型项目中的应用
- Selenium的PO模式(Page Object Model)[python版]
- selenium+java+testNG+pageObject深入理解自动化测试框架
- Selenium的PO模式(Page Object Model)[python版]
- Selenium(Python)PageObject页面对象
- Selenium的PageFactory & PageObject 在大型项目中的应用
- Selenium2学习-012-WebUI自动化实战实例-010-解决元素失效:StaleElementReferenceException: stale element reference: element is not attached to the page document
- selenium page object model
- Page Object Model (Selenium, Python)
- Selenium Page Object Model-FindAll annotation
- Selenium的PageFactory & PageObject 在大型项目中的应用
- Python+Selenium框架设计--- Page Object Model
- Selenium+Python :WebDriver设计模式( Page Object )
- Page Object Model (POM) & Page Factory in Selenium: Ultimate Guide
- Page Object Model (Selenium + Python)(三)
- Selenium的PO模式(Page Object Model)|(Selenium Webdriver For Python)
- Selenium Page object Pattern usage
- Page Object Model (Selenium, Python)(一)
- Selenium Page Object(PO)设计模式