python - 如何防止每次运行测试用例时移动应用程序关闭并重新打开?

标签 python automation appium python-unittest

我正在使用 Appium 和 Python 执行移动应用程序自动化。我还需要创建 HTML 报告。我也想创建多个测试套件。所有这些都有效,除了一个问题。

我的问题是应用程序在每个测试用例中都会关闭并重新打开。我怎样才能解决这个问题?提前致谢。

(请注意,这是我放在这里的示例代码。)

from adb.client import Client as AdbClient
import HtmlTestRunner
import datetime
import os, sys
import glob
import unittest
from appium import webdriver
from time import sleep
from appium.webdriver.common.touch_action import TouchAction

PLATFORM_VERSION = '8.1.0'



class Q_suite1_01(unittest.TestCase):

def setUp(self):
    desired_caps = {}
    desired_caps['platformName'] = 'Android'
    desired_caps['platformVersion'] = '8.1.0'
    desired_caps['deviceName'] = 'Samsung Galaxy J7 Max'

    devices = AdbClient(host= "127.0.0.1", port= 5037).devices()
    for device in devices:
        desired_caps['udid'] = device.serial

    desired_caps['appPackage'] = 'com.testapp'
    desired_caps['appActivity'] = 'com.testapp.MainActivity'
    url = "http://localhost:{}/wd/hub".format(4723)
    self.driver = webdriver.Remote(url, desired_caps)




def install(self):
    print 'ABDC!'


def run_app(self):
    try:
        x = self.driver.is_app_installed('com.quallogi')
        if x is True:
            print 'App is already installed.'
        else:
            print 'App is not installed.'
    except:
        print 'App not installed'


def signin(self):
    sleep(5)
    self.driver.find_element_by_xpath('//*[contains(@text,"Login") and contains(@class, "android.widget.TextView")]').click()
    print 'Sign'


def testcase_Install_app(self):
    self.install()

def testcase_Run_app(self):
    self.run_app()

def testcase_SignIn(self):
    self.signin()


# def testcase_Install_app(self):
#     self.install()
#     self.run_app()
#     self.signin()
#



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



if __name__ == '__main__':

     result = []

     suite1= unittest.TestLoader().loadTestsFromTestCase(Q_suite1_01)
     result.append(HtmlTestRunner.HTMLTestRunner(output='./HTML Reports/' 
     + str(datetime.date.today())).run(suite1))
     print(result)

最佳答案

首先,我想推荐您查看 Appium 功能“noReset”——“在此 session 之前不要重置应用程序状态。” (真假)。

如果我没看错你的问题。您是什么意思“应用程序在每个测试用例中关闭并重新打开”?能详细说说吗?

关于python - 如何防止每次运行测试用例时移动应用程序关闭并重新打开?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57074283/

相关文章:

ios - 是否可以在 Ubuntu 上运行 Appium iOS 自动化测试?

python - 在ubuntu上将django sqlite数据库迁移到mysql

appium - 使用 Appium 如何检查我们的应用程序正在运行或关闭或最小化

java - 在 Appium Java Android 测试中单击菜单项时页面源未更新

r - 在目录中导入最新的 csv 文件

ios - 在仪器中找不到 UI 记录器模板

python - Linux 下 Python 中与 GUI 元素的脚本交互

python - 在 xarray dataarray 中重命名 __xarray_dataarray_variable__

python - 轴标签的 Matplotlib DateFormatter 不起作用

python - 树莓派 - psutil 安装错误