首页 > 解决方案 > 使用 Appium 和 Python for IOS 从另一个测试脚本自动调用另一个测试脚本

问题描述

我正在使用 Appium 和 Python 创建一些测试,以在 IOS 中测试我的应用程序的基本 UI 元素。我目前有两个 Python 脚本来测试两个不同的 VC。理想情况下,我希望每个 VC 都有一个单独的测试脚本。但是,我真的希望能够在当前运行的 Python 脚本结束时调用下一个测试脚本。

到目前为止,我在第一个 VC 的最终测试中使用语法“subprocess.Popen('python test_appium_authCodeRegister.py 1', shell=True)”调用下一个脚本,但是,当我在终端中运行测试时,它只在第一个测试脚本之后显示“7 在 107.74 秒内通过”绿色文本,而不是第二个。

尽管第二个脚本当前在第三个脚本之后运行(因为它在第一个脚本的最后一次测试中被调用),但终端没有给我任何关于测试是否通过的反馈。

请在下面找到我的代码。

我尝试将调用下一个脚本的函数放在脚本的最底部但没有成功,而不是在自己的测试方法中调用它。

import subprocess
import pytest
import test_appium_authCodeRegister
import unittest
import os
from random import randint
from appium import webdriver
from time import sleep
from selenium.webdriver.common.keys import Keys

class LoginTests(unittest.TestCase):

def setUp(self):

    app = ('/Users/Brian/Documents/Projects/funtimeapp/build/Release-iphonesimulator/funtimeapp .app')
    self.driver = webdriver.Remote(
        command_executor='http://127.0.0.1:4723/wd/hub',
        desired_capabilities={
            'app': app,
            'platformName': 'iOS',
            'platformVersion': '12.1',
            'deviceName': 'iPhone XR',
            'autoAcceptAlerts': 'true'
        }
    )

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

@pytest.mark.run(order=1)
def testDisabledLoginButton(self):
    self.driver.implicitly_wait(3)
    loginButton = self.driver.find_element_by_accessibility_id('loginButton')
    loginButton.click()
    self.assertTrue(loginButton.is_enabled)
    print loginButton.is_enabled()

@pytest.mark.run(order=2)
def testInstitutionField(self):
    self.driver.implicitly_wait(2)
    institution = "tesco"
    institutionField = self.driver.find_element_by_accessibility_id('institutionField')
    institutionField.send_keys(institution)
    institutionField.send_keys(Keys.RETURN)
    self.driver.implicitly_wait(2)
    self.assertEqual(institutionField.get_attribute("value"), institution)

@pytest.mark.run(order=3)
def testUsernameField(self):
    self.driver.implicitly_wait(2)
    username = "geez1"
    usernameField = self.driver.find_element_by_accessibility_id('usernameField')
    usernameField.send_keys(username)
    usernameField.send_keys(Keys.RETURN)
    self.driver.implicitly_wait(2)
    self.assertEqual(usernameField.get_attribute("value"), username)

@pytest.mark.run(order=4)
def testPasswordField(self):
    self.driver.implicitly_wait(2)
    password = "Password1"
    passwordField = self.driver.find_element_by_accessibility_id('passwordField')
    passwordField.send_keys(password)
    passwordField.send_keys(Keys.RETURN)
    self.driver.implicitly_wait(2)
    self.assertEqual(passwordField.get_attribute("value"), password)

@pytest.mark.run(order=5)
def testRegisterButton(self):
    self.driver.implicitly_wait(2)
    self.driver.find_element_by_accessibility_id('registerButton').click()
    self.driver.implicitly_wait(4)
    authCodeTextField = self.driver.find_element_by_accessibility_id('authTextField')
    self.assertTrue(authCodeTextField.get_attribute('wdVisible'))

@pytest.mark.run(order=6)
def testLogin(self):
    self.driver.implicitly_wait(2)
    self.testInstitutionField()
    self.testUsernameField()
    self.testPasswordField()
        self.driver.find_element_by_accessibility_id('loginButton').click()
    self.driver.implicitly_wait(10)
    welcomeView =     self.driver.find_element_by_accessibility_id('welcome')
    self.assertTrue(welcomeView.get_attribute('wdVisible'))

@pytest.mark.run(order=7)    
def testNextScript(self):
    subprocess.Popen('python test_appium_authCodeRegister.py 1', shell=True)


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

标签: pythoniosappium

解决方案


推荐阅读