一、PageObject六大原则
1、The public methods represent the services that the page offers
公共方法表示页面提供的服务
2、Try not to expose the internals of the page
尽量不要暴露页面的内部结构
3、Generally dont't make assertions
一般不做断言
4、Methods return other PageObjects
方法返回其他PageObject
5、Need not represent an entire page
不需要代表整个页面,只需要封装重要的页面元素
6、Different results for the same action are modeled as different methods
同一动作的不同结果被建模为不同的方法
二、复用谷歌浏览器
只对谷歌浏览器有效,此处是windows10中的配置
2.1、需要退出当前所有的谷歌浏览器(特别注意)
关闭浏览器时,设置中一定要关闭后台数据同步,否则会复用浏览器失败。
设置 -> 搜索“后台同步” -> 点击“网站设置” -> 点击“后台同步” ->关闭“禁止最近关闭…”右侧的按钮
浏览器不能缩放,需要调整为100%
2.2、找到chrome的启动路径
谷歌浏览器图标鼠标右键 -> 属性 -> 目标
路径只需要截取到Application即可
C:\Program Files\Google\Chrome\Application
2.3、配置环境变量
将谷歌启动路径,加入到环境变量中
同时需要注意的是,需要将谷歌浏览器的驱动chromedriver也同样加入到环境变量中。一般放入python安装路径中即可。
2.4、启动命令
命令行中输入启动命令
# windows
chrome --remote-debugging-port=9222
# mac
Google/Chrome --remote-debugging-port=9222
2.5、验证是否复用成功
命令行启动浏览器,地址栏输入:127