Lets spread the test automation awesomeness with Windows Test Automation with Windows Application Driver

Lets spread the test automation awesomeness with Windows Test Automation with Windows Application Driver

Test automation is limitless and there is no boundaries. Test automation has grown from Web UI to Web Services, Windows and Mobile.

Today in this article I'm gonna show how we can kick start Windows application test automation with WinApp Driver.

First of all create a Java Maven project and add the following dependencies.

  <dependency>
	<groupId>org.seleniumhq.selenium</groupId>
	<artifactId>selenium-java</artifactId>
	<version>3.3.9</version>
 </dependency>
<dependency>
    <groupId>io.appium</groupId>
    <artifactId>java-client</artifactId>
    <version>7.0.0</version>
</dependency>

Next we have to make the machine run on Windows developer mode.

Then we need to download the Microsoft windows application driver.

Finally we write a test automation scenario for our Windows Calculator program.

package CalculatorPkg;
	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;
	import org.testng.*;
	import org.testng.annotations.BeforeClass;
	import org.testng.annotations.Test;
	public class CalculatorClass {
		    private static WindowsDriver CalculatorSession = null;
		    private static WebElement CalculatorResult = null;
		@BeforeClass
	    public static void setup() {
	        try {
	            DesiredCapabilities capabilities = new DesiredCapabilities();
	            capabilities.setCapability("app", "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App");
	            CalculatorSession = new WindowsDriver(new URL("https://127.0.0.1:4723"), capabilities);
	            CalculatorSession.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

	            CalculatorResult = CalculatorSession.findElementByAccessibilityId("CalculatorResults");
	            Assert.assertNotNull(CalculatorResult);
	

	        }catch(Exception e){
	            e.printStackTrace();
	        } finally {
	        }
	    }
	

	

	    protected String _GetCalculatorResultText()
	    {
	        // trim extra text and whitespace off of the display value
	        return CalculatorResult.getText().replace("Display is", "").trim();
	    }
		
	@Test
	public void testCalc()
	{
		  CalculatorSession.findElementByName("Two").click();
	      CalculatorSession.findElementByName("Plus").click();
	      CalculatorSession.findElementByName("Three").click();
	      CalculatorSession.findElementByName("Equals").click();
	      Assert.assertEquals("5", _GetCalculatorResultText());
	}
		
	}

Windows elements can be inspected via inspect tool which comes in Windows SDK

No alt text provided for this image


要查看或添加评论,请登录

社区洞察

其他会员也浏览了