I'm automating testing on iOS & Android devices with pytest and Appium. Consider the following:
some_locator:
{
'iOS': ('MobileBy.ACCESSIBILITY_ID', 'some_id'),
'Android': ('MobileBy.ID', 'another_id')
}
def foo():
bar = driver.find_element(some_locator)
return bar.text
I want to run the script with either 'ios'
or 'android'
parameter from the command line to make function find_element
use the corresponding tuple values.
Also I know that I can do like this:
# conftest.py
def pytest_addoption(parser):
parser.addoption("--platform", default="ios")
@pytest.fixture
def cmdopt(request):
return request.config.getoption("--platform")
# some_file.py
some_locator:
{
'iOS': ('MobileBy.ACCESSIBILITY_ID', 'some_id'),
'Android': ('MobileBy.ID', 'another_id')
}
def foo(platform):
if platform == 'ios':
bar = find_element(*some_locator['ios'])
elif platform == 'android':
bar = find_element(*some_locator['android'])
return bar.text
but frankly speaking, I don't like it that way, because I'll have to add these if
blocks in every method.
Is there any convenient way to do it? My python is bad so I can't figure out the solution, please advice.