Python Forum
How to pass a dictionary as an argument inside setup function of unittest
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to pass a dictionary as an argument inside setup function of unittest
#1
Basically I am writing an appium code to automate one native app. Now what I want is that instead of hard coding the capabilities I want to use an external dictionary which will provide data to my test case regarding all capabilities.How can I achieve that

here is my main programm

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)
Also the code which is going to return a dictionary is

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
Reply


Messages In This Thread
How to pass a dictionary as an argument inside setup function of unittest - by nilaybnrj - May-03-2019, 09:24 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in using unittest akbarza 2 335 Feb-25-2024, 12:51 PM
Last Post: deanhystad
  mutable argument in function definition akbarza 1 492 Dec-15-2023, 02:00 PM
Last Post: deanhystad
  How to pass encrypted pass to pyodbc script tester_V 0 873 Jul-27-2023, 12:40 AM
Last Post: tester_V
  with open context inside of a recursive function billykid999 1 589 May-23-2023, 02:37 AM
Last Post: deanhystad
  How do I call sys.argv list inside a function, from the CLI? billykid999 3 801 May-02-2023, 08:40 AM
Last Post: Gribouillis
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 1,107 Dec-25-2022, 03:00 PM
Last Post: askfriends
  passing dictionary to the function mark588 2 983 Dec-19-2022, 07:28 PM
Last Post: deanhystad
Question Unwanted execution of unittest ThomasFab 9 2,078 Nov-15-2022, 05:33 PM
Last Post: snippsat
  i want to use type= as a function/method keyword argument Skaperen 9 1,897 Nov-06-2022, 04:28 AM
Last Post: Skaperen
  unittest.mock for an api key silver 3 1,400 Aug-29-2022, 03:52 PM
Last Post: ndc85430

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020