在appium中,如何在不运行测试的情况下将测试用作另一个测试的依赖项?

时间:2016-01-05 15:13:55

标签: python appium

我试图在appium中创建一些测试,但是当我第一次运行应用程序时,我必须通过使用条款屏幕并首先运行屏幕。

由于我只需要执行一次这些步骤,因此我很难运行其他测试(当我已经运行这些屏幕时)。

关于我该怎么做的任何想法?

import os, unittest, time
from appium import webdriver
from time import sleep

class Tests(unittest.TestCase):
    def setUp(self):
        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '5.1'
        desired_caps['deviceName'] = '0429058934'
        desired_caps['app'] = os.path.abspath(os.path.join(os.path.dirname(__file__),'mypath'))
        desired_caps['appPackage'] = ''
        desired_caps['appActivity'] = '.MainActivity'
        desired_caps['fullReset'] = True
        self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
        self.driver.implicitly_wait(30)

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

    def first_run(self):
        self.driver.find_element_by_id("p_agreement_btn").click()
        next = self.driver.find_element_by_id("next_text")
        next.click()
        next.click()
        next.click()
        next.click()
        self.driver.find_element_by_id("btn_ok").click()

    def test_optimization(self):
        self.driver.find_element_by_id("new_powerpro_tab_view_text").click()
        self.driver.find_element_by_id("optimization_button").click()       

if __name__ == '__main__':
    suite = unittest.TestLoader().loadTestsFromTestCase(Tests)
    unittest.TextTestRunner(verbosity=2).run(suite)

2 个答案:

答案 0 :(得分:1)

你正在使用python的UnitTest框架,它不像TestNg那样支持依赖。如果你想创建依赖测试,那么你使用Proboscis测试框架,它具有像TestNg一样的功能。通过以上链接阅读文档特别注释,如" @test(depends_on = [UserTests.successful_login])"

答案 1 :(得分:-1)

为此你可以使用长鼻。

参考链接:https://pythonhosted.org/proboscis/