这是我写的 web ui 自动化脚本


UI 自动化脚本已经部署到了 jenkins

这个是接口自动化的脚本,接口自动化目前还没有往 jenkins 部署

我就是想知道,我这跟公司真实的自动化还缺了那些东西,或者说我写的哪里不对?
以后的计划是把框架进行封装,写自动化测试平台
这是我写的 web ui 自动化脚本



这个是接口自动化的脚本,接口自动化目前还没有往 jenkins 部署

我就是想知道,我这跟公司真实的自动化还缺了那些东西,或者说我写的哪里不对?
以后的计划是把框架进行封装,写自动化测试平台
未知地区 20F
好了,已经解决了上面的问题了,但是不知道为什么会启动两次浏览器,我再看看
未知地区 19F
def find_element(self, lc, locator,timeout=”):
“””元素定位”””
if lc == “xpath”:
ele = WebDriverWait(self.driver, timeout=10)
.until(EC.visibility_of_element_located((By.XPATH,locator)))
class Login_Page_Locator(BasePage):
“””登录页元素定位”””
username = (‘xpath’, ‘//input[@placeholder=”请输入用户名”]’)
password = (‘xpath’, ‘//input[@placeholder=”请输入密码”]’)
submit = (‘xpath’,’//span[text()=”登录”]’)
class Test_Login(object):
loginpage = Login_Page_Locator()
base = BasePage()
@allure.story(“登录用例”)
@allure.severity(allure.severity_level.BLOCKER)
def test_login1_normal(self):
“””username and passwd is normal”””
Logger().info(‘test_login success’)
try:
#输入用户名
self.base.find_element(self.loginpage.username[0],self.loginpage.username[1]).send_keys(username)
except NoSuchElementException:
Logger().error(‘login no find element’)
#assert username == “admin”
#insert_img(“login_normal.png”)
为什么我这样写,一直在定位元素
未知地区 18F
嗯是这样的
未知地区 17F
元素的定位方式和用例数据可以单独抽离出来,实现脚本与数据分离
未知地区 16F
可以参考下 RF 的设计 ,动作就是动作 元素就是元素
执行用例时 就是元素 + 动作 来完成一次操作 比如
1、用户名元素 + 输入 (参数)
2、密码元素 + 输入(参数)
3、登录按钮元素 + 左键点击
打个比方
类似于 selenium 本身也封装了 click 方法
你可以再封装一层 把 driver.click + Action 类的 Click + JavaScript 的 Click 封装到一起 做成自定义的动作 myClick 简化脚本开发的操作
未知地区 15F
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_123venvlibsite-packagesseleniumwebdriversupportwait.py”, line 81, in until
value = method(self._driver)
File “D:demo_123venvlibsite-packagesseleniumwebdriversupportexpected_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
未知地区 14F
好的
未知地区 13F
楼主,代码可以贴代码。markdown 的代码块。别截图。
未知地区 12F
一些常用的输入,点击,可以封装在基类页面吗
未知地区 11F
页面基类只维护页面公共元素 动作另外封装