python - 如何在unittest的设置函数中将字典作为参数传递
问题描述
基本上我正在编写一个 appium 代码来自动化一个本机应用程序。现在我想要的是,我不想对功能进行硬编码,而是使用一个外部字典,它将为我的测试用例提供有关所有功能的数据。我怎样才能实现这一点
这是我的主要程序
from appium import webdriver
from time import sleep
from pathlib2 import Path
import os
from appium.webdriver.common.touch_action import TouchAction
import unittest
class report(unittest.TestCase):
def setUp(self):
""""Launch the settings"""
capabilities = {}
capabilities["platformName"] = "Android"
capabilities["platformVersion"] = "8.0.0"
capabilities["deviceName"] = "Nil_Emulator"
capabilities["app"] = os.path.abspath(str(Path(__file__).parents[1]) + "/apk/medical-wisdom-1.0.8.apk")
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', capabilities)
self.driver.implicitly_wait(30)
def tearDown(self):
self.driver.quit()
def test_report(self):
element_best_practice = self.driver.find_elements_by_xpath("//android.widget.RelativeLayout[@index=0]")
action = TouchAction(self.driver)
action.tap(element_best_practice[4]).perform()
sleep(3)
element_report_record = self.driver.find_element_by_xpath("//android.widget.ImageView[@index=1]")
action.tap(element_report_record).perform()
sleep(3)
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(report)
unittest.TextTestRunner(verbosity=2).run(suite)
还有要返回字典的代码是
from devices import DeviceSelection
import subprocess
class getOS(DeviceSelection):
def __init__(self):
super(getOS,self).__init__()
self.dict = {}
def getdata(self):
for device in self.list:
output = subprocess.check_output("adb -s " + device+" shell getprop ro.build.version.release ",shell=True)
self.dict[device]= output
return self.dict
解决方案
推荐阅读
- javascript - 在 Vue 中使用可变等待时间去抖动输入
- rust - Serde/jsonrpc-core:转换为相同数据的表示
- google-colaboratory - 我想在 Google colab 中安装 tensorflow 1.14 版但失败了
- reactjs - React useEffect 依赖破坏了值传递
- powershell - Powershell WebSocket(ClientWebSocket) 发送消息
- c# - 当子类从父类继承时,有没有办法为继承的字段使用不同的数据类型来添加更多功能?
- html - 将 ngx 时间选择器绑定到 Angular 中的表单控件
- org-mode - org 模式将 NAME 赋予时钟表以使用 perl 解析
- java - Spring Boot 无法访问外部文件
- java - 如何在java类中获得相同的@XmlElement名称