i have a problem with switching file with xpaths and test data for appPackage that is currently under tests:
tests.py
@pytest.fixture(params=brand_list)
def driver(request):
desired_caps = {
"platformName": "Android",
"platformVersion": "10.0",
"deviceName": "moto",
"appPackage": request.param.appPackage,
"appActivity": "com.appname.MainActivity",
"automationName": "UiAutomator2"
}
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
yield driver
driver.quit()
brand_list
and brand_name
are declared in other file:
brand_configs
brand_list = [xpaths.brand1, xpaths.brand2, xpaths.brand3, xpaths.brand4, xpaths.brand5, xpaths.brand5]
brand_name = xpaths.brand1
And here is an sample test from tests.py file:
@pytest.mark.order(1)
def test_enter_login(driver):
login_page.enter_user_and_password(driver)
assert generic_elements.check_home_button_is_visible(driver)
Functions that are used to find elements are located in other files like "login_page.py" etc, for example:
def enter_password(driver_instance):
elem = wait_for_visibility_of_element(driver_instance=driver_instance, xpath=brand_name.password_path)
return elem
Test run result:
File tree:
As on picture, I have no clue how to pass different brand_name
value for enter_login
test for brands 2-6. Because of that tests are failing.
I have tried many things to solve this problem. When I try to move brand_name
to main tests.py
folder, I always get
ImportError: cannot import name '...' from partially initialized module '...' (most likely due to a circular import)
It's probably because tests.py
is importing files like login_page.py
mentioned above, and they are using brand_name from brand_configs
.
I have also tried to set brand_name
to the value of currently active app activity, but this also fails, because app is not started yet with tests session.
Maybe there is an easy way force app that is currently under tests to use correct xpaths_file
declared as brand_name in brand_configs.py
?
When brand_name
is set to one specific value, tests are correctly performed for that appPackage
.