先简单说说什么是参数化,已百度为例平时我们测试搜索,每次我们测试一个不同的搜索内容,都需要更改参数的值。在这个过程里面,除了数据在变动以外,其他步骤都是重复的。
这个时候我们就可以使用参数化的方式来代替数据的变动。参数化顾名思义就是把不同的参数,写到一个列表里,或者说写到一个集合里面。然后让程序自动去这个列表里面取值,直到列表为空便结束。
import pytest
from appium import webdriver
import time
# todo pytest里面类名也要已test开头
class Test_Search_():
def setup_class(self):
desired_caps = {
"platformName": "Android",
"platformVersion": "5.1",
"deviceName": "127.0.0.1:62001",
"appPackage": "com.android.settings",
"appActivity": ".Settings",
"noreset": "True"
}
# todo 获得驱动对象
self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
@pytest.mark.parametrize("content",[1,3])
def test_search(self,content):
self.driver.find_element_by_id('com.android.settings:id/search').click()
self.driver.find_element_by_id('android:id/search_src_text').send_keys(content)
time.sleep(1)
if __name__ == '__main__':
pytest.main(["-s", "search.py"])