Automate Universal Windows Platform (UWP) Application in Visual Studio using Appium
Universal Windows Platform, commonly knows as UWP. Microsoft provides a single app development framework which can be
deployed to multiple devices which run on windows 10 devices like phone/surface/PC etc. In this topic we would go through the UWP
automation of the 'News App'(Desktop) using the Appium framework. Appium is a open source test automation tool for mobile apps.
The winappdriver uses the default selenium properties. Appium uses selenium API to automation the UI elements.
2. Winappdriver - Download from https://github.com/Microsoft/WinAppDriver/releases
1. Creating a new unit test project in visual studio. Launch visual studio and goto file->new->project.
Add references through nuget manager. Right Click on the solution and click on Manage Nuget Packages. Search for Appium and install it.
Add the below code to the *.cs file. Compile and run the test using the test explorer. Ensure the winappdriver.exe is running
parallel'ly for execution. This is available @ C:\Program Files (x86)\Windows Application Driver
namespace News_Appium
{
[TestClass]
public class NewsTest
{
protected const string WindowsApplicationDriverUrl = "https://127.0.0.1:4723";
protected static WindowsDriver<WindowsElement> NewsApp;
protected static WindowsDriver<WindowsElement> DesktopSession;
[ClassInitialize]
public static void Setup(TestContext context)
{
DesiredCapabilities appCapabilities = new DesiredCapabilities();
appCapabilities.SetCapability("app", "Microsoft.BingNews_8wekyb3d8bbwe!AppexNews");
NewsApp = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities);
Assert.IsNotNull(NewsApp);
DesiredCapabilities desktopCapabilities = new DesiredCapabilities();
desktopCapabilities.SetCapability("app", "Root");
DesktopSession = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), desktopCapabilities);
Assert.IsNotNull(DesktopSession);
}
[ClassCleanup]
public static void TearDown()
{
NewsApp.Quit();
}
[TestMethod]
public void TopNav()
{
NewsApp.FindElementByName("My News").Click();
NewsApp.FindElementByName("My Sources").Click();
string text = NewsApp.FindElementByName("Your News. Your Sources.").Text.ToString();
Assert.AreEqual("Your News. Your Sources.", text);
NewsApp.FindElementByName("Top Stories").Click();
NewsApp.FindElementByName("US").Click();
NewsApp.FindElementByName("World").Click();
NewsApp.FindElementByName("Good News").Click();
NewsApp.FindElementByName("Politics").Click();
NewsApp.FindElementByName("Opinion").Click();
NewsApp.FindElementByName("Crime").Click();
NewsApp.FindElementByName("Technology").Click();
NewsApp.FindElementByName("Entertainment").Click();
NewsApp.FindElementByName("Money").Click();
NewsApp.FindElementByName("Sports").Click();
AppiumWebElement searchbox = NewsApp.FindElementByName("Search");
searchbox.Clear();
searchbox.SendKeys("Microsoft\r\n");
string txtBlock = NewsApp.FindElementByClassName("TextBlock").Text;
Assert.AreEqual(txtBlock, "Microsoft");
}
}
}
Compile the code and run the test using the test explorer The above code will use the News App Pre-installed in the windows 10
devices. Or you can use the store app(bing news) to install the app. ''Microsoft.BingNews_8wekyb3d8bbwe!AppexNews" is the app
package name of the bing news app used in the above code.
As the winappdriver is evolving, there would be suffice support from the open source community for any issues. Ex: for sending the text in
the textbox(key+enter), user as to use the escape sequence like \r\n. Like Textbox.sendkeys("Microsoft\r\n").
You can always check the updated versions in https://github.com/Microsoft/WinAppDriver
- Anonymous
June 09, 2017
I am regular reader, how are you everybody? This post posted at this site is actually pleasant.|