from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as ec
class Page():
def __init__(self):
self.driver = webdriver.Chrome()
def open(self):
self.driver.get("https://www.baidu.com")
self.driver.maximize_window()
def __find_element__(self, lc, locator):
"""元素定位"""
if lc == "id":
ele = self.driver.find_element(By.ID, locator)
print(type(ele))
WebDriverWait(self.driver, 10).until(ec.visibility_of_element_located(ele))
a=Page()
a.open()
a.__find_element__('id','kw').send_keys('python')
我打算重构的 basepage 页,简单调试了下,报了这个错
<class 'selenium.webdriver.remote.webelement.WebElement'>
Traceback (most recent call last):
File "D:/demo_123/basic/page.py", line 48, in <module>
a.__find_element__('id','kw').send_keys('python')
File "D:/demo_123/basic/page.py", line 19, in __find_element__
WebDriverWait(self.driver, 10).until(ec.visibility_of_element_located((ele)))
File "D:\demo_123\venv\lib\site-packages\selenium\webdriver\support\wait.py", line 81, in until
value = method(self._driver)
File "D:\demo_123\venv\lib\site-packages\selenium\webdriver\support\expected_conditions.py", line 125, in _predicate
return _element_if_visible(driver.find_element(*locator))
TypeError: find_element() argument after * must be an iterable, not WebElement
好的
一些常用的输入,点击,可以封装在基类页面吗
嗯,我设计的确实这块问题很大,已经在重构了,打算封装一个基类 basepage 把启动浏览器,元素定位的类型,操作等单独封装起来
这是在测试用例里面的加的 log 日志,断言,用例成功后的截图
https://blog.csdn.net/dream_back/article/details/118751500
我找了一篇博客,看了别人封装的 po,觉得我现在的 po 有很大问题,定位元素的部分太过繁琐,而且还把业务的测试流程放在 page 里了
看了,你的回复,我先修改下 ui 自动化的测试框架,UI 的问题,你说的 1,2,3, 2 和 3 有做,但是还是有问题,1 我用的隐式等待和强制等待,觉得不太好,打算改
最近在研究这方面的东西,就是想知道,我写的这个跟真实的公司做自动化差别在哪里?
看完你们就一个感觉,学历那么高的优势,怎么都在做测试,难道做开发不香,开发不是比测试薪资高多了吗?
嗯,已经改了,现在好了
好了,解决了,太感谢了
好的,我试试
嗯,已经改了,把文本拿出来了进行对比的
有说是我 linux 下浏览器驱动和浏览器版本不一致导致的,但是我查了大版本是一致的
那一般怎么断言呢,像这种表单操作,添加,编辑,删除之类的,我还想的弹出的提示,用提示信息进行断言
对,我是那添加成功的提示信息,定位到这个文本的元素,然后进行对比
嗯嗯,是只启动了一次,问题找到了,就是第一个用例执行完,就把 driver 给关了,导致第二个用例找不到,现在已改成用夹具 fixture,问题已解决
确实是这方面的问题,我已经改成用夹具 fixture 把 driver 放在外部,还有登录,也就是说我所有的用例,只启动一次 driver,只登录一次,然后跑完所有的测试用例,再调用 fixture 里的 driver.quit() 进行关闭浏览器
你问的是单个用例吗?我是把 driver 单独封装了个方法,然后每个测试用例的 前置类操作里 调用了 driver
这是写的两个用例
你的意思是 docker 容器里最好什么都不要装是吧
你说的 2,我理解了一下,也找了相关的资料,找到了一篇文章,你看下是不是就以这种方式安装,安装在 linux 宿主机商
https://www.cnblogs.com/wjafl/p/16523043.html
你说的第一种情况我看了不是,我进的就是原来的容器
通过接口,估计也得一次次执行,可以通过直接改数据库
我也不知道啊,本想找到部署环境的节点发,但是没找到