WinAppDriver icon indicating copy to clipboard operation
WinAppDriver copied to clipboard

Appium : How to run the UWP Desktop app in background for couple of seconds and launch the app from the same state?

Open gouthamsam opened this issue 9 years ago • 4 comments

driver.runAppInBackground(30);

This command doesn't work for UWP.

gouthamsam avatar Jul 25 '17 11:07 gouthamsam

Pls check this ticket I opened before, it should solve your problem: https://github.com/Microsoft/WinAppDriver/issues/184

holphi avatar Jul 25 '17 13:07 holphi

Hi @gouthamsam,

Windows Application Driver doesn't currently support that Appium specific command. Can you provide the scenario you are trying to replicate and the spec on what the command does?

timotiusmargo avatar Aug 17 '17 03:08 timotiusmargo

I am testing a UWP app, where I want to run the app in background for couple of minutes to check some screen customizations and bring it back to the same state. In general, for iOS and android driver, it supports that command where the app will stay in background for couple of minutes and come back to the previous state of activity. Scenario: Button color customization.

  1. Clicking on the button and change it's color to some random color. We defined a timer in the UWP app and after couple of minutes. It will revert back to the same color.
  2. I want to test this scenario, by running the UWP App in background. I tried with the Sendkeys to minimize the App and Restore it after couple of minutes. getAppiumDriver().getKeyboard().sendKeys(Keys.META,String.valueOf('\u006D'),Keys.META ); sleep(30); //Restoring the app from background getAppiumDriver().getKeyboard().sendKeys(Keys.META,Keys.SHIFT,String.valueOf('\u006D'),Keys.META);
  3. The problem I'm facing with sendkeys is somehow the pressed state of the hot keys still remains selected and other tests were getting failed. For example: getStaticAnswer() is a textbox field. for (int i = 0; i < 3; i++) { getStaticAnswer(i).click(); getStaticAnswer(i).sendKeys(Integer.toString(i)); } Now instead of "0" it types "(" in the first field and so on.

Thank you

gouthamsam avatar Aug 22 '17 10:08 gouthamsam

Hi @gouthamsam,

I see. From your description above, you are simulating your test scenario by minimizing all windows using Alt +m keyboard shortcut and restoring them with Alt + Shift + m. Looks like you have most of the code in place with just a missing Shift key release to stop the key from being held down indefinitely.

In the code snippet you sent, the Shift key was sent once and was never released. As a result 0 is typed as ) and so on. Quoting JSON Wire Protocol SendKeys API document:

The modifiers are not released at the end of the call. Rather, the state of the modifier keys is kept between calls, so mouse interactions can be performed while modifier keys are depressed.

Below is a sample snippet code in C# to do what you are attempting to do. Notice the extra Keys.Shift after the m to release the key modifier.

// Press Windows keys followed by 'm' to minimize all windows
session.Keyboard.SendKeys(Keys.Meta + 'm' + Keys.Meta);

// Press Windows keys followed by Shift and 'm' to restore the windows
session.Keyboard.SendKeys(Keys.Meta + Keys.Shift + 'm' + Keys.Shift + Keys.Meta);

I would also consider only minimizing the particular window instead of all windows if you are interested about your particular app. For example:

// Save the current window size
var windowSize = session.Manage().Window.Size;

// Press Windows keys followed by two Arrow Down keys to minimize current active window
session.Keyboard.SendKeys(OpenQA.Selenium.Keys.Meta + OpenQA.Selenium.Keys.ArrowDown + OpenQA.Selenium.Keys.ArrowDown + OpenQA.Selenium.Keys.Meta);

// Wait for couple minutes or do any other useful operation
System.Threading.Thread.Sleep(TimeSpan.FromMinutes(2));

// Restore the minimized window to the saved window size
session.Manage().Window.Size = windowSize;

timotiusmargo avatar Aug 22 '17 22:08 timotiusmargo