6_appium:测试用例改造

之前录制的测试脚本,是一个最基础的测试脚本,还需要通过一些改造,通过一些测试框架的支撑,才能成为在项目中使用的测试用例。

测试框架的选择:

  • java推荐testNG
  • python推荐pytest

创建pytest用例有多种形式,我们最常用的是以下这种:

# content of test_class.py
class TestClass:
    def test_one(self):
        x = "this"
        assert "h" in x

    def test_two(self):
        x = "hello"
        assert hasattr(x, "check")

基于pytest改造的用例如下:

from appium import webdriver


class TestDemo:
    def setup(self):
        caps = {
     }
        caps["platformName"] = "Android"
        caps["deviceName"] = "d0a49989"
        caps["appPackage"] = "com.android.contacts"
        caps["appActivity"] = "com.android.contacts.activities.TwelveKeyDialer"
        caps["noReset"] = True

        self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", caps)
        self.driver.implicitly_wait(10)

    def test_demo(self):
        el1 = self.driver.find_element_by_accessibility_id("一")
        el1.click()
        el2 = self.driver.find_element_by_accessibility_id("零")
        el2.click()
        el2.click()
        el3 = self.driver.find_element_by_accessibility_id("八")
        el3.click()
        el4 = self.driver.find_element_by_accessibility_id("六")
        el4.click()
        el5 = self.driver.find_element_by_accessibility_id("拨打电话")
        el5.click()

    def teardown(self):
        self.driver.quit()

首次在PyCharm中执行,需要修改一下默认执行测试用例的配置,将Unittests修改为pytest

6_appium:测试用例改造_第1张图片

你可能感兴趣的:(Appium)