使用Appium和Python for IOS从另一个测试脚本自动调用另一个测试脚本

时间:2019-01-16 10:50:27

标签: python ios appium

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

到目前为止,在第一个VC中的最终测试中,我正在使用语法“ subprocess.Popen('python test_appium_authCodeRegister.py 1',shell = True)”调用下一个脚本,因为我在在终端上,它仅在第一个测试脚本之后(而不是第二个)显示“ 7 in 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)

0 个答案:

没有答案