mercredi 13 janvier 2021

Changing session in python unittest using Appium and WinAppDriver

I'm testing windows application.

The first step is to start the application launcher and select the database. The next step is to log in directly to the application - not in the launcher, which is closed after first step. Therefore, I need to switch the session (in my code it is handler) from the launcher to applications in one test. How to do it correctly?

My handlers:

class Handlers:
    def launcherHandler(self):
        desired_caps = {}
        desired_caps["app"] = Data.programu
        launcherDriver = webdriver.Remote(
            command_executor='http://127.0.0.1:4723',
            desired_capabilities=desired_caps)
        return launcherDriver

    def applicationHandler(self):
        desired_caps = {}
        desired_caps["app"] = "Root"
        self.driver = webdriver.Remote(
            command_executor='http://127.0.0.1:4723',
            desired_capabilities=desired_caps)
        WebDriverWait(self.driver, 50).until(EC.element_to_be_clickable((By.NAME, 'App')))
        AppWindow = self.driver.find_element_by_name('App')
        AppTopLevelWindowHandle = AppWindow.get_attribute("NativeWindowHandle")
        AppTopLevelWindowHandle = hex(int(AppTopLevelWindowHandle))
        appCapabilities = {}
        appCapabilities["appTopLevelWindow"] = AppTopLevelWindowHandle
        appSession = webdriver.Remote(
            command_executor='http://127.0.0.1:4723', desired_capabilities=appCapabilities)
        appSession.maximize_window()
        return appSession

My test method:

class Tests:
    def myTest(self, handler1, handler2, name):
        Methods.wait(self, handler1, Locators.appWindowName)
        Methods.elementIdClick(self, handler1, Locators.baseComboBoxId)
        Methods.elementNameClick(self, handler1, Locators.newPodmiotName)
        Methods.elementIdClick(self, handler1, Locators.simpleRadioButtonId)
        Methods.textBoxIdSendKeys(self, handler1, Locators.nameTextBoxId, name)
        Methods.elementIdClick(self, handler1, Locators.runButtonId)
        Methods.elementIdClick(self, handler1, Locators.runButtonId)
        Methods.wait(self, handler2, Locators.appWindowName)

And finally my test:

class test(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.handler1 = Handlers.launcherHandler(self)
        self.handler2 = Handlers.applicationHandler(self)

    def test(self):
        Tests.myTest(self, self.handler1, self.handler2, Data.name)

if __name__ == '__main__':
    suite = unittest.TestLoader().loadTestsFromTestCase(test)

After closing the launcher (handler1), the test does not wait for the program to open (handler2). I know I probably shouldn't be calling handler2 in SetUpClass, but I have no other idea. How to fix it?

Could you help me?

Aucun commentaire:

Enregistrer un commentaire