def test_data():
# 打开Excel文件
path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
openExcelFile = open_workbook(path + "/config/data.xlsx")
# 获取工作表
getSheet = openExcelFile.sheet_by_name("Sheet1")
# 获取行数
rowNumber = getSheet.nrows
# 数据List
dataList = []
# 从第二行开始遍历每一行
for i in range(1, rowNumber):
# 把每个单元格的数值存放到dataLis
dataList.append(getSheet.row_values(i))
return dataList
"""浴室管理"""
class Bathroom_Func(BasePage):
def add_bathroom(self):
lp = BasePage(self._driver)
"""
点击右上角“新增”按钮进入新增浴室界面
:return:
"""
try:
self._driver.find_element_by_android_uiautomator('new UiSelector().resourceId("com.qekj.merchant:id/iv_add")').click()
except Exception as e:
self._driver.get_screenshot_as_file(lp.screenshot_filepath())
return self
@pytest.mark.parametrize("bathroom_name", test_data())
def message_complete(self, bathroom_name):
lp = BasePage(self._driver)
"""
完善新增浴室信息
"""
sleep(1)
try:
self._driver.find_element_by_android_uiautomator(
'new UiSelector().resourceId("com.qekj.merchant:id/et_device_name")').send_keys(bathroom_name)
self._driver.find_element_by_android_uiautomator(
'new UiSelector().resourceId("com.qekj.merchant:id/tv_store_name")').click()
sleep(1)
self._driver.find_element_by_android_uiautomator(
'new UiSelector().text("确定")').click()
sleep(1)
self._driver.find_element_by_android_uiautomator(
'new UiSelector().resourceId("com.qekj.merchant:id/tv_sex")').click()
self._driver.find_element_by_android_uiautomator(
'new UiSelector().text("确定")').click()
self._driver.find_element_by_android_uiautomator(
'new UiSelector().text("提交")').click()
except Exception as e:
self._driver.get_screenshot_as_file(lp.screenshot_filepath())
return self
@pytest.mark.parametrize("bathroom_name",test_data())
def delete_bathroom(self,bathroom_name):
"""删除新增浴室"""
action1 = 'new UiSelector().text{bathroom_name}'.format(bathroom_name=bathroom_name)
action2 = 'new UiSelector().text("删除")'
self._driver.find_element_by_android_uiautomator(action1).click()
self._driver.find_element_by_android_uiautomator(action2).click()
return self
在 test_data() 函数里打印一下dataList是不是返回空了,看样子是这个函数的数据没获取到
你报错的函数位置和上面的不是一个地方吧?报错的函数是 test_add_bathroom,上面的是 message_complete
哦哦,test_add_bathroom这个是PO模式下的case部分,实际上是在调用message_complete函数方法时报的错
还有测试用例默认类名是Test开头,函数是test_开头呀,你咋不一样,是自己定义了吗
只是运行了类文件下的test_add_bathroom方法
解决了,@pytest.mark.parametrize需要在pytest框架下执行,所以,我所有的类、方法名称都需要改成pytest格式