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’
}
}

PageObject的更多相关文章

  1. UI自动化测试框架(项目实战)python、Selenium(日志、邮件、pageobject)

    其实百度UI自动化测试框架,会出来很多相关的信息,不过就没有找到纯项目的,无法拿来使用的:所以我最近就写了一个简单,不过可以拿来在真正项目中可以使用的测试框架. 项目的地址:https://githu ...

  2. 浅谈pageobject模式

    先来看两段代码 代码1: package com.zlshuo.selenium.nonaming.pageobject; /** * @author leshuo * @version 2014年5 ...

  3. page-object使用(2)---elements

    elements就是html元素下所有的标签.用page-object你可以找到并定位html页面下绝大多数的元素,这个文章列出了可定位的这些元素,生成的方法,和依据什么关键字来找到这些元素. BUT ...

  4. page-object使用(1)

    创建你的page 你必须做的第一件事情是创建你的page,这是一些包含了PageObject模块的简单的ruby类,请不要创建你自己的initialize方法,因为已经有一个存在而且不能被覆盖.如果你 ...

  5. Page-Object设计模式

    自动化脚本初写之际一定是只求完成功能测试,页面by.id.by.name.by.xpath满篇飞.业务逻辑代码重复率也是越来越高.慢慢的写着写着开始重构,开始封装一些方法.代码量好一些的人会在代码开始 ...

  6. selenium更加高效的PageObject 对象操作代码

    重新封装了的selenium代码,包括click事件,sendkeys事件,select事件,以及对readonly日期控件的处理 package com.common; import java.ut ...

  7. PageObject设计模式,在selenium自动化测试中的运用

    PageObject设计模式1. Web自动化测试框架(WebTestFramework)是基于Selenium框架且采用PageObject设计模式进行二次开发形成的框架. 2. web测试时,建议 ...

  8. 记我的第二次自动化尝试——selenium+pageobject+pagefactory实现自动化下单、退款、撤销回归测试

    需求: 系统需要做下单.退款.撤销的回归测试,有下单页面,所以就想到用selenium做WEB UI 自动化 项目目录结构: common包上放通用的工具类方法和浏览器操作方法 pageobject包 ...

  9. 【转】Webdriver的PageObject改造By 张飞

    Webdriver的PageObject改造 PageObject中提供了一个@FindBy注解,也非常好用,但由于其是一次性全部初始化所有的WebElement,对于当前还不存在于页面上的Eleme ...

  10. pageObject学习

    1.java代码层面的pageObject实现 参考:https://www.cnblogs.com/yytesting/p/6973474.html 是用java写的实例,优点是结构很清晰,缺点是p ...

随机推荐

  1. Go同步等待组/互斥锁/读写锁

    1. 临界资源 package main import ( "fmt" "time" ) func main() { /* 临界资源: */ a := 1 go ...

  2. yii2的防御csrf攻击机制

    csrf,中文名称:跨站请求伪造,可以在百度上搜索资料,详细了解这一方面的概念.对于我们是非常有帮助的.yii2的csrf的实现功能是在yii\web\request类实现功能的.request类中的 ...

  3. layuiAdmin std v1.x 【iframe版】开发者文档

    layuiAdmin pro v1.x [单页版]开发者文档 layuiAdmin.std(iframe 版) 是完全基于 layui 架构而成的通用型后台管理模板系统,采用传统的 iframe 多页 ...

  4. Error: Cannot find module 'webpack' 问题解决办法

    这句话的意思是:没有找到webpack模块. 就算之前你装了webpack,那肯定是非全局安装 所以要全局安装 npm install --save-dev webpack 问题解决

  5. CentOS7重启和关机

    重启命令: 1.reboot 2.shutdown -r now 立刻重启(root用户使用) 3.shutdown -r 10 过10分钟自动重启(root用户使用) 4.shutdown -r 2 ...

  6. SpringBoot+mongoDB实现id自增

    这段时间给朋友做了一个微信小程序,顺便练习一下spring boot,虽然项目使用的是JPA+MySQL,但是好奇尝试了一下MongoDB实现自增ID,虽然MongoDB很少有自增ID的需求(在分布式 ...

  7. BugReport-智慧农业APP

    1.展示的界面显示不全 bug Description: 测试环境:win10.工具eclipse: 测试步骤:打开运行程序后模拟器启动,第一个界面显示过几秒跳到了另一个界面,问题是第一个界面显示不全 ...

  8. C语言:计算输出给定数组中每相邻两个元素的平均值的平方根之和。

    //计算输出给定数组中每相邻两个元素的平均值的平方根之和. #include <stdio.h> #include <math.h> ]) { double a,b,s=0.0 ...

  9. pandas read excel or csv

    import pandas as pd """pandas doc:df.dtypes 查看数据每column 数据类型 id int64x0 float64df.rei ...

  10. Springboot中使用kafka

    注:kafka消息队列默认采用配置消息主题进行消费,一个topic中的消息只能被同一个组(groupId)的消费者中的一个消费者消费. 1.在pom.xml依赖下新添加一下kafka依赖ar包 < ...