PageObject
2015-07-11 15:11
330 查看
import org.openqa.selenium.WebDriver; import org.openqa.selenium.ie.InternetExplorerDriver; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.support.PageFactory; import org.openqa.selenium.support.PageFactory; public class BasePage { public static WebDriver driver; public static BaiduHomepage get(String url) throws InterruptedException { System.setProperty("webdriver.ie.driver", "IEDriverServer.exe文件的路径"); // 设置系统环境变量,key-value DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer(); ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true); driver=new InternetExplorerDriver(ieCapabilities); // 实例化一个浏览器对象 driver.get(url); return PageFactory.initElements(driver, BaiduHomepage.class); } public static void quit() { driver.quit(); } }
import org.openqa.selenium.By; 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; //百度主页 public class BaiduHomepage extends BasePage{ private WebDriver driver; @FindBy(id = "kw") public WebElement kw; public BaiduHomepage(WebDriver driver) { this.driver=driver; } public BaiduListPage searchListPage(String key) { try { Thread.sleep(10000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("keyWords="+kw); kw.sendKeys("selenium"); return PageFactory.initElements(driver, BaiduListPage.class); } }
import org.openqa.selenium.WebDriver; //搜索结果页面 public class BaiduListPage extends BasePage{ private WebDriver driver; public BaiduListPage( WebDriver driver) { this.driver=driver; } }
package pageObject; import org.openqa.selenium.support.PageFactory; public class TestClass { /** * @param args * @throws InterruptedException */ public static void main(String[] args) throws InterruptedException { new BasePage().get("www.baidu.com").searchListPage("selenium");//在百度搜索关键字‘selenium’ } }
相关文章推荐
- id、NSObject、id<NSObject>三者的区别
- mysql_fetch_row,mysql_fetch_array,mysql_fetch_object,mysql_fetch_assoc的区别!
- Objective-C语法之代码块(block)的使用
- Objective-C内存管理
- IOS学习笔记01-关于objective-c的成员属性
- [Objective-C] 用 dispatch_once 实现单例
- 【iOS开发之Objective-C】复合
- 【Ray Tracing from Ground Up】Ray-Object Interserctions
- Using JPA and JAXB Annotations in the Same Object
- 【JSON异常系列】new JSONObject对象时卡死原因
- Java String类和Object类
- [学习笔记—Objective-C]《Objective-C 程序设计 第6版》第十八章 复制对象
- CodeBlocks集成Objective-C开发
- Objective-C MacOS的管理员权限继承
- Objective-C MacOS以管理员权限运行程序
- 说说 Objective-C 里的 @()
- Object-c的继承、封装、多态
- What does it mean to write `static void * ptr = &ptr` in objective-c?
- [Objective-C] Cocoa's Target-Action Pattern
- iwebshop (: Cannot use object of type stdClass as array in)