Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WindowsHandles: Currently selected window has been closed #656

Open
burakdnbb opened this issue Apr 3, 2019 · 20 comments
Open

WindowsHandles: Currently selected window has been closed #656

burakdnbb opened this issue Apr 3, 2019 · 20 comments

Comments

@burakdnbb
Copy link

Hello everyone,

I have a question regarding the splash screen problem. @timotiusmargo mentioned in previous topics, that the problem with the window handles and the splash screen has been fixed as of release 1.1.1 (see issues #621 and #611). Is it included in this pre-release of the winappdriver, or is the fix still in progress? We checked the latest commits of this pre release 1.1.1 and did not see any changes compared to the previous version.

Right now we are trying to automate the Microsoft Dynamics NAV Client and we still have this issue with the splash screen. We also checked that the processid is the same (between splash screen and the new window that opens) Could you provide some info on that?

Thanks in advance

@anunay1
Copy link

anunay1 commented Apr 3, 2019

How long does the splash screen stay, even I faced issues while trying to automate an application with splash screen. If the splash screen stays for more than 3sec then it does not acquire session, you need to use the existing session.

@burakdnbb
Copy link
Author

The splash screen stays around 5-10 seconds.

@timotiusmargo
Copy link
Contributor

Hi @burakdnbb,

Thanks for reaching out and bring up the issue. A splash screen window is a UI element that is a part of the application UI experience. When desired, WinAppDriver can be used to automate against the splash screen to validate certain UI elements such as texts and progress bar.

In most cases however, people are much more interested in the main application window that typically appears after the splash screen. When creating a new session (launching an application), WinAppDriver treats the first appearing top level application window (including a splash screen window) as the main window of the application and performs every operation against it. This becomes a hindrance for developers who only care about the main application window and want to ignore the splash screen altogether. Below are the top recommended options to circumvent such scenario.

1. If possible, launch the application with a no splash screen flag/option

Certain application takes a command line argument to launch without showing a splash screen window. For example, you can launch Microsoft Word, Excel, and PowerPoint without splash screen as follows:

"C:\Program Files (x86)\Microsoft Office\root\Office16\WINWORD.EXE" /q
"C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE" /e
"C:\Program Files (x86)\Microsoft Office\root\Office16\POWERPNT.EXE" /s

You can provide the command line argument in the appArguments capabilities as shown in the example below.
https://github.com/Microsoft/WinAppDriver/tree/v1.1.1#testing-a-classic-windows-application

2. Manually switch the session to the desired top level application window

Starting in v1.1.1 release, you can enumerate all the top level application windows using GetWindowHandles command and switch to the desired application window using SwitchToWindow command. Prior to this release, you can only enumerate the top level windows when the current window handle is still active. Hence this command used to fail when the session was pointing to a splash screen window that has already disappeared. The latest release allows you to enumerate all application windows even when the current active window is closed.

In your scenario where a splash screen appears for 5 seconds until the main application window appears, calling the GetWindowHandles multiple times during this application startup period allows you to detect when the splash screen is dismissed and when the new application window is ready to be switched into.

3. Create a new session by attaching to an existing window

Attaching to existing window is by far the most versatile approach as it can attach to any top level window even the one with different process Id. Nevertheless, you will potentially need to use another session to locate the top level window handle which is less straight forward from both options above.

@YouWhy
Copy link

YouWhy commented Apr 9, 2019

How do I do this with RobotFramework + AppiumLibrary?

@anunay1
Copy link

anunay1 commented Apr 10, 2019

You can do that in test initialize

@YouWhy
Copy link

YouWhy commented Apr 12, 2019

@anunay1 can you give me some example code in order to do this? There are two problems:

  1. For example if I launch outlook, then the splash screen goes away and it launches the main window. How do I attach to that?
  2. How do I attach to a window that is already open (not launched by Appium)?

@timotiusmargo
Copy link
Contributor

Hi @YouWhy,

Attaching to existing window section shows how to use a Desktop session to locate any currently active window/UI element on the desktop. This generic approach also allows you to cover both scenarios you mentioned above:

  1. Launch an application with splash screen
  • Launch application (e.g. Outlook)
  • Wait for the splash screen to disappear and the main window to appear
  • Use Desktop Session to locate the main window and attach to it
  1. Attach to window that is already open
  • Use Desktop Session to locate the desired window and attach to it

Another example can also be found below:
https://github.com/Microsoft/WinAppDriver/blob/v1.1.1/Samples/C%23/CortanaTest/BingSearch.cs#L97

@YouWhy
Copy link

YouWhy commented Apr 16, 2019

@timotiusmargo Thank you for your pointers, but my problem is that I am using the Appium Client Library in Robot Framework. How do I access the Desktop Session in this development environment? Am I limited to what I can do if I choose Appium Client Library + (RobotFramework OR Python)? If yes, then I need to abandon this Proof of Concept and look at using C# for automation. Can you please advice? My teams are blocked by this and cannot proceed till this is resolved.

Appreciate your response.

@timotiusmargo
Copy link
Contributor

Hi @YouWhy,

You can use any binding and programming language of your choice. To create a Desktop Session, you simply need to create a new session with root as your appId. E.g.

DesiredCapabilities appCapabilities = new DesiredCapabilities();
appCapabilities.SetCapability("app", "Root");
DesktopSession = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), appCapabilities);

While the object names (e.g. DesiredCapabilities, WindowsDriver) may vary between different language bindings, the same parameter value should work with corresponding object in any binding.

@YouWhy
Copy link

YouWhy commented Apr 19, 2019

@timotiusmargo that worked!! I was able to create a desktop session and find the main outlook window and manipulate it after the splash screen disappeared. Thank you so much. However, I did face another issue. While trying to delete the session after I was done, Outlook was still open. That did not happen with a UWP app that I was working on. Why is that? Is that a limitation of WinAppDriver?

@timotiusmargo
Copy link
Contributor

Hi @YouWhy,

I'm glad you got it working 👍 As long as your session points to the right application window, calling session.close() or session.quit() should implicitly attempt to close that particular window. If you have multiple Outlook windows open, you will need to go through each of them to close it as shown in the following sample:
https://github.com/Microsoft/WinAppDriver/blob/v1.1.1/Tests/WebDriverAPI/Window.cs#L185

@YouWhy
Copy link

YouWhy commented Apr 22, 2019

@timotiusmargo I use the "Close All Applications" keyword provided by Appium that sends an API call to close each open open session one by one. The Winappdriver console shows each of these calls it returns success STATUS 200 OK. So I am curious as to why this is happening...Could this be an issue?

@sarthakmahapatra9
Copy link

Hi @burakdnbb,

Thanks for reaching out and bring up the issue. A splash screen window is a UI element that is a part of the application UI experience. When desired, WinAppDriver can be used to automate against the splash screen to validate certain UI elements such as texts and progress bar.

In most cases however, people are much more interested in the main application window that typically appears after the splash screen. When creating a new session (launching an application), WinAppDriver treats the first appearing top level application window (including a splash screen window) as the main window of the application and performs every operation against it. This becomes a hindrance for developers who only care about the main application window and want to ignore the splash screen altogether. Below are the top recommended options to circumvent such scenario.

1. If possible, launch the application with a no splash screen flag/option

Certain application takes a command line argument to launch without showing a splash screen window. For example, you can launch Microsoft Word, Excel, and PowerPoint without splash screen as follows:

"C:\Program Files (x86)\Microsoft Office\root\Office16\WINWORD.EXE" /q
"C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE" /e
"C:\Program Files (x86)\Microsoft Office\root\Office16\POWERPNT.EXE" /s

You can provide the command line argument in the appArguments capabilities as shown in the example below.
https://github.com/Microsoft/WinAppDriver/tree/v1.1.1#testing-a-classic-windows-application

2. Manually switch the session to the desired top level application window

Starting in v1.1.1 release, you can enumerate all the top level application windows using GetWindowHandles command and switch to the desired application window using SwitchToWindow command. Prior to this release, you can only enumerate the top level windows when the current window handle is still active. Hence this command used to fail when the session was pointing to a splash screen window that has already disappeared. The latest release allows you to enumerate all application windows even when the current active window is closed.

In your scenario where a splash screen appears for 5 seconds until the main application window appears, calling the GetWindowHandles multiple times during this application startup period allows you to detect when the splash screen is dismissed and when the new application window is ready to be switched into.

3. Create a new session by attaching to an existing window

Attaching to existing window is by far the most versatile approach as it can attach to any top level window even the one with different process Id. Nevertheless, you will potentially need to use another session to locate the top level window handle which is less straight forward from both options above.

Hi @timotiusmargo, I am using the following code to open a powerpoint file. But the code is opening 2 windows 1) the default Powerpoint window and then 2) The file. It does all the operations in the default powerpoint window file instead of the given file. Can you please check -

desired_caps = {}
desired_caps["app"] = "POWERPNT.EXE"
desired_caps["appArguments"] = os.getcwd() + '\' + 'MyPowerpoint.pptx' + ' /s'
self.driver = webdriver.Remote(command_executor='http://127.0.0.1:4723',desired_capabilities=desired_caps)
self.driver.set_page_load_timeout(20)

@naeemakram
Copy link

I've launched Excel with the code given below. It works fine.

 DesiredCapabilities dcExcel = new DesiredCapabilities();
            dcExcel.SetCapability("app", @"C:\Program Files (x86)\Microsoft Office\Office15\EXCEL.exe");
            dcExcel.SetCapability("appArguments", "/e");
            WindowsDriver<WindowsElement> sessionExcel = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), dcExcel);

@qa-atish
Copy link

qa-atish commented Dec 23, 2019

is this possible to open a saved Excel file with winapp driver? When I try to open this.
Error :
"message": "An unknown error occurred in the remote end while processing the command."

I checked the settings where I permit it

@naeemakram
Copy link

Yes, it is possible to open a saved file with Excel. Just pass the file path in as a desired capability.

DesiredCapabilities dcExcel = new DesiredCapabilities();
            dcExcel.SetCapability("app", @"C:\Program Files (x86)\Microsoft Office\Office15\EXCEL.exe");
            dcExcel.SetCapability("appArguments", "C:\YourFolder\YourFile.xlsx");
            WindowsDriver<WindowsElement> sessionExcel = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), dcExcel);

@qa-atish
Copy link

Thanks for the help @naeemakram :).is this possible to edit some cells in excel with winappdriver ?

@naeemakram
Copy link

Thanks for the help @naeemakram :).is this possible to edit some cells in excel with winappdriver ?

You're welcome, no it is not possible to edit Excel cells according to my experience.
It is somewhat possible to read the values of the sheet(Ctrl+C) if your test script is running at the machine same as Excel AUT.

@qa-atish
Copy link

Thanks. Will you help me: I have to edit some values in the excel sheet and after that need to read the output. How I can perform this.
Any other tool you used @naeemakram

@naeemakram
Copy link

Maybe you could use VBA scripting for this purpose, there's an Office development SDK as well. I'm not sure since I haven't done this type of work before. Don't think I will be able to help in this specific case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants