I am developing a program with Python 3.7 and Appium 1.15
The program will run parallel test on real Android devices. I need to pass parameters to the function which will run the test on a specific smartphone.
These parameters are the desired capabilities (udid, os version, devicename, etc….).
So my idea was to create a method in myownmodule.py which will receive the parameters and pass it to the Class object.
The best way to explain my idea is to share my code:
But I have no idea how to pass the parameters received by my function to my test Class and method.
I search on Google and I couldn’t find the answer to my question. I typed “python pass parameters from my function to a class inside my function”, but it doesn’t give me the accurate answer.
A second problem may come, I need this unittest test running properly Appium test.
If some expert could help the newbie I am to find solution to this complex programming issue, please?
Why are you defining the class that creates the webdriver instance inside a function? It’s much better if you define it as a separate class and then instantiate it in the module where your function is defined.
and my class definition like this? class auto1(unittest.TestCase,p_name_action,p_udid, p_systemPort, p_deviceName, p_version, p_os,quantity_tasks_per_hit):
Thank you so much. I am using unittest. I am not good enough to use other test framework.
When you said
Just pass along the parameters in a dictionary
.You mean I stored my parameters in a dictionary “mydict” and add it in the unittest line of code as parameter, like this? suite = unittest.TestLoader().loadTestsFromTestCase(auto1(mydict))
?
If that option is allowed in the unittest framework, then yes. That way, you won’t have to specify every parameter and when you instantiate the driver with an invalid parameter in the dictionary it’ll throw an exception.
unittest might be good enough, but it depends on how you want to develop your solution. You might want to google it a bit. This is a good starting point: