Parameterization of pytest

Briefly talk about what is parameterized, has Baidu, for example we usually test search, every time we test a different search content, you need to change the value of the parameter. In this process which, in addition to the data fluctuation than the other steps are repeated.

This time we can use instead of a parameterized way to change the data. Parameterized by definition is the different parameters, writes a list, or a set of written inside. Then let the program automatically go to this value inside the list until the list is empty then ended.

 

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"])

 

Guess you like

Origin www.cnblogs.com/xiamaojjie/p/11495179.html