0

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:

testrun

File tree:

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.

STerliakov
  • 4,983
  • 3
  • 15
  • 37
art rtr
  • 1
  • 1

1 Answers1

0

from the screenshot you added, it can be seen that you are trying to send different xpaths within one session and not between different sessions as u mentioned, accordingly, it will not work because capabilities are the same

If I understand properly you have a list of apps and a list of XPath, and you want to run the same test for the different apps, but how it will work if you started a session for one app and try to run for this app different sets of xpaths

  • Hi Dmytro, thanks for reply. Mechanism for launching 6 different apps to test_login_page one after another is working correctly, and if assert would be for element with the same xpath, all of them would pass. All I need, it to somehow change brand_name value when second app is launched, to acces file with xpaths that are in xpaths.brand2 file. All I want to do, is to test all brands with one test launch, now i have to perform test of brand1, change value on brand_name to xpaths.brand2, and test_login_page will know that brand2 is I have add another picture of file tree in main thread. – art rtr Dec 22 '22 at 15:59
  • OK got it, from the described logic you get the brand name from brand_config.py. This is a hard-coded value and brand XPath depends on this value. – Dima Berezovskyi Dec 22 '22 at 16:33
  • What logic does the bran_config.py file contain – Dima Berezovskyi Dec 22 '22 at 16:39