51Testing软件测试论坛
标题: Selenium PageFactory使用 [打印本页]
作者: 一针 时间: 2017-3-19 22:28
标题: Selenium PageFactory使用
通过FindBy查找元素
@FindBy(id="notice01")
private WebElement username;
相当于driver.findElement(By.id("notice01"));
示例:
- 示例:
- (1)测试类:
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.chrome.ChromeDriver;
- import org.testng.Assert;
- import org.testng.annotations.Test;
- import com.train.loginPage;
- import org.testng.annotations.BeforeClass;
- import org.testng.annotations.AfterClass;
- import org.openqa.selenium.support.PageFactory;
- public class test_01 {
-
- public static WebDriver driver =null;
-
- @BeforeClass
- public void beforeClass() {
- System.out.println("Begin");
-
- }
-
- @Test
- public void chooseSeat() throws InterruptedException{
- System.setProperty("webdriver.chrome.driver", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe");
- driver = new ChromeDriver();
- loginPage m =PageFactory.initElements(driver,loginPage.class);
- driver.get("http://www.baidu.com");
- m.Search(driver,"selenium测试");
-
- }
-
- @AfterClass
- public void afterClass() {
- System.out.println("end ");
-
- }
-
- }
复制代码 (2)元素类:
执行后
百度文本框中输入"selenium测试"
[attach]105178[/attach]
作者: 梦想家 时间: 2017-3-20 09:07
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) |
Powered by Discuz! X3.2 |