microsoft / WinAppDriver

Windows Application Driver
MIT License
3.7k stars 1.41k forks source link

Sometimes WinAppDriver runs fast and other times it runs slow , any Explanation ? #1472

Closed zahraazezo closed 3 years ago

zahraazezo commented 3 years ago

When running WinAppDriver automated tests , it runs fast sometimes and slow most of times , informing that there are no other running application .

anunay1 commented 3 years ago

What is the command time out given?

zahraazezo commented 3 years ago

@anunay1 It was 60 seconds , I changed it to be 120

new WindowsDriver(remoteAddress, appiumOptions, TimeSpan.FromSeconds(120));

as it was always throwing The HTTP request to the remote WebDriver server for URL http://127.0.0.1:4723/session/C31E5E62-EB73-4392-A659-063F46FE1F11/element timed out after 60 seconds. exception while locating any element using xpath

anunay1 commented 3 years ago

xpath is slow and that's a known issue with WAD, better to use other method to find the element. I have not used it all all in my project.

zahraazezo commented 3 years ago

@anunay1
Thank you so much for reply

I know , unfortunately there are nested elements that I need to locate and I have to use xpath to locate them

, but I want to know why it sometimes t runs fast even with xpath (not fast as the other locators , but in accepted way ) and sometimes not ?

shoaibmansoor commented 3 years ago

@zahraazezo What I have observed is that winappdriver caches older sessions which were not terminated properly with quit() method. From python, I can list all older sessions by driver.all_sessions property.

What I am doing to avoid this is to close all older sessions at test start.

# Appium stops responding after several runs. It is because it stores old sessions data which makes it laggy.
# To avoid this issue, clear old sessions at the first session initiation request
if self.is_desktop and UiDriver.dump_old_desktop_sessions:
    current_session_id = session.session_id
    old_sessions = list(filter(lambda i: i.get('id') != current_session_id, session.all_sessions))
    for it in old_sessions:
        session.command_executor.execute(Command.QUIT, {'sessionId': it.get('id')})

I think restarting winappdriver before each test should also do the job

zahraazezo commented 3 years ago

@shoaibmansoor Sorry for my late reply , you are right .it worked for me Thank you so much

Pavithra2304 commented 2 years ago

Am using C# Visual Studio for Desktop Automation using WinApp session, But it is taking more time to find an Element. But am not using any wait or Thread.Sleep. But the OverAll Test Cases is taking more time. Any Solution or alternative for this???

anunay1 commented 2 years ago

What's more time? How much time does it take. What is the command timeout you have given?

Pavithra2304 commented 2 years ago

It is taking more than 10 seconds to find an element in the page. I didn't give any timeout command.

anunay1 commented 2 years ago

By default the timeout is 60 seconds.

Shakevg commented 2 years ago

Am using C# Visual Studio for Desktop Automation using WinApp session, But it is taking more time to find an Element. But am not using any wait or Thread.Sleep. But the OverAll Test Cases is taking more time. Any Solution or alternative for this???

Try this https://github.com/microsoft/WinAppDriver/issues/1472#issuecomment-1121094052

sarthakmahapatra9 commented 1 year ago

@shoaibmansoor , I am getting error when I try to use this code. What are these variables? there is no method called driver.all_sessions. Would Greatly appreciate your help.

# Appium stops responding after several runs. It is because it stores old sessions data which makes it laggy.
# To avoid this issue, clear old sessions at the first session initiation request
if self.is_desktop and UiDriver.dump_old_desktop_sessions:
    current_session_id = session.session_id
    old_sessions = list(filter(lambda i: i.get('id') != current_session_id, session.all_sessions))
    for it in old_sessions:
        session.command_executor.execute(Command.QUIT, {'sessionId': it.get('id')})