Date: Thu, 28 Mar 2024 13:05:22 +0000 (UTC) Message-ID: <1390828192.10217.1711631122856@docs.getxray.app> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_10216_934482398.1711631122854" ------=_Part_10216_934482398.1711631122854 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
In this tutorial, we will create a JUnit Test Case in Java, using the Appium<= /a> library for automation of Windows applications.
The following automated test class validates the "Calculator" Windows na= tive application using several methods (i.e., Tests) for validating each ar= ithmetic operation.
Please note
This example is taken from the public Github repository https://github.com/Microsoft/Wi= nAppDriver/tree/master/Samples/Java/CalculatorTest. It also provid= es examples for other languages.
WinAppDriver.exe 192.168.56.102 4723
We will make a simple update to the pom.xml file in order to generate a = JUnit xml report.
<project xmlns=3D"http://maven.apache.org/POM/4.0.0" xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=3D"http://maven.apache.org/POM/4.0.0 http://mav= en.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>CalculatorTest</groupId> <artifactId>CalculatorTest</artifactId> <version>1.0-SNAPSHOT</version> <dependencies> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>3.3.1</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency> <dependency> <groupId>io.appium</groupId> <artifactId>java-client</artifactId> <version>5.0.0-BETA6</version> </dependency> </dependencies> <reporting> <plugins> <plugin> <artifactId>maven-surefire-report-plugin</artifact= Id> </plugin> </plugins> </reporting> </project>
The class implementing the automated tests needs to be updated in order = to properly set up the IP of the Appium server.
//****************************************************************= ************** // // Copyright (c) 2016 Microsoft Corporation. All rights reserved. // // This code is licensed under the MIT License (MIT). // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS = OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL = THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING = FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS I= N // THE SOFTWARE. // //*************************************************************************= ***** import org.junit.*; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.DesiredCapabilities; import java.util.concurrent.TimeUnit; import java.net.URL; import io.appium.java_client.windows.WindowsDriver; public class CalculatorTest { private static WindowsDriver CalculatorSession =3D null; private static WebElement CalculatorResult =3D null; @BeforeClass public static void setup() { try { DesiredCapabilities capabilities =3D new DesiredCapabilities(); capabilities.setCapability("app", "Microsoft.WindowsCalculator_= 8wekyb3d8bbwe!App"); CalculatorSession =3D new WindowsDriver(new URL("http://192.168= .56.102:4723"), capabilities); CalculatorSession.manage().timeouts().implicitlyWait(2, TimeUni= t.SECONDS); CalculatorResult =3D CalculatorSession.findElementByAccessibili= tyId("CalculatorResults"); Assert.assertNotNull(CalculatorResult); }catch(Exception e){ e.printStackTrace(); } finally { } } @Before public void Clear() { CalculatorSession.findElementByName("Clear").click(); Assert.assertEquals("0", _GetCalculatorResultText()); } @AfterClass public static void TearDown() { CalculatorResult =3D null; if (CalculatorSession !=3D null) { CalculatorSession.quit(); } CalculatorSession =3D null; } @Test public void Addition() { CalculatorSession.findElementByName("One").click(); CalculatorSession.findElementByName("Plus").click(); CalculatorSession.findElementByName("Seven").click(); CalculatorSession.findElementByName("Equals").click(); Assert.assertEquals("8", _GetCalculatorResultText()); } @Test public void Combination() { CalculatorSession.findElementByName("Seven").click(); CalculatorSession.findElementByName("Multiply by").click(); CalculatorSession.findElementByName("Nine").click(); CalculatorSession.findElementByName("Plus").click(); CalculatorSession.findElementByName("One").click(); CalculatorSession.findElementByName("Equals").click(); CalculatorSession.findElementByName("Divide by").click(); CalculatorSession.findElementByName("Eight").click(); CalculatorSession.findElementByName("Equals").click(); Assert.assertEquals("8", _GetCalculatorResultText()); } @Test public void Division() { CalculatorSession.findElementByName("Eight").click(); CalculatorSession.findElementByName("Eight").click(); CalculatorSession.findElementByName("Divide by").click(); CalculatorSession.findElementByName("One").click(); CalculatorSession.findElementByName("One").click(); CalculatorSession.findElementByName("Equals").click(); Assert.assertEquals("8", _GetCalculatorResultText()); } @Test public void Multiplication() { CalculatorSession.findElementByName("Nine").click(); CalculatorSession.findElementByName("Multiply by").click(); CalculatorSession.findElementByName("Nine").click(); CalculatorSession.findElementByName("Equals").click(); Assert.assertEquals("81", _GetCalculatorResultText()); } @Test public void Subtraction() { CalculatorSession.findElementByName("Nine").click(); CalculatorSession.findElementByName("Minus").click(); CalculatorSession.findElementByName("One").click(); CalculatorSession.findElementByName("Equals").click(); Assert.assertEquals("8", _GetCalculatorResultText()); } protected String _GetCalculatorResultText() { // trim extra text and whitespace off of the display value return CalculatorResult.getText().replace("Display is", "").trim(); } }
Tests can be run using Maven.
mvn clean test
After successfully running the Test cases and generating the JUnit XML r= eport (e.g., TEST-CalculatorTest.xml), it can = be imported to Xray (either by the REST API or through the Import E= xecution Results action within the Test Execution).
Each JUnit's Test Case is mapped to a Generic Test in Jira, and the
The Execution Details of the Generic Test contains information about the= Test Suite, which in this case corresponds to the Test Case class. = p>