WinAppDriver Test Example

  • WinAppDriver Test Example
    • install WinAppDriver
    • Enable Developer Mode in Windows settings
    • Run WinAppDriver.exe from the installation directory
    • create an IDEA maven project
    • pom.xml
    • Sample Test Code
    • Run Result
    • 例外
    • 参考

WinAppDriver Test Example

install WinAppDriver

Download Windows Application Driver installer from https://github.com/Microsoft/WinAppDriver/releases

Enable Developer Mode in Windows settings

Run WinAppDriver.exe from the installation directory

(E.g. C:\Program Files (x86)\Windows Application Driver)
double click the exe file and you can see

create an IDEA maven project

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.winappdriver.test</groupId><artifactId>winappdriver-test</artifactId><version>1.0-SNAPSHOT</version><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target></properties><dependencies><!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java --><dependency><groupId>org.seleniumhq.selenium</groupId><artifactId>selenium-java</artifactId><version>3.141.59</version></dependency><!--<! — https://mvnrepository.com/artifact/org.testng/testng →--><dependency><groupId>org.testng</groupId><artifactId>testng</artifactId><version>7.1.0</version><scope>test</scope></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.11</version></dependency><!-- https://mvnrepository.com/artifact/io.appium/java-client --><dependency><groupId>io.appium</groupId><artifactId>java-client</artifactId><version>7.3.0</version></dependency></dependencies></project>

Sample Test Code

import io.appium.java_client.windows.WindowsDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;import java.net.URL;
import java.time.LocalDate;
import java.util.concurrent.TimeUnit;public class NotepadTest {private static WindowsDriver notepadSession = null;public static String getDate(){LocalDate date = LocalDate.now();return date.toString();}@BeforeClasspublic static void setUp() {try {DesiredCapabilities capabilities = new DesiredCapabilities();capabilities.setCapability("app", "C:\\Windows\\System32\\notepad.exe");capabilities.setCapability("platformName","Windows");capabilities.setCapability("deviceName", "WindowsPC");notepadSession = new WindowsDriver(new URL("http://127.0.0.1:4723"), capabilities);notepadSession.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);} catch (Exception e) {e.printStackTrace();}}@AfterMethodpublic void cleanApp(){notepadSession.quit();setUp();}@AfterSuitepublic void tearDown(){notepadSession.quit();}@Testpublic void checkAboutWindow() {notepadSession.findElementByName("Help").click();notepadSession.findElementByName("About Notepad").click();notepadSession.findElementByName("OK").click();}@Testpublic void sendTestText(){notepadSession.findElementByClassName("Edit").sendKeys(getDate());notepadSession.findElementByClassName("Edit").clear();}@Test()public void pressTimeAndDateButton(){notepadSession.findElementByName("Edit").click();notepadSession.findElementByAccessibilityId("26").click();Assert.assertNotNull(notepadSession.findElementByClassName("Edit"));notepadSession.findElementByClassName("Edit").clear();}
}

Run Result


例外

如果没有打开开发人员模式,将会运行不了WinAppDriver.exe,运行测试用例会产生错误

Driver info: driver.version: WindowsDriverat io.appium.java_client.remote.AppiumCommandExecutor.lambda$5(AppiumCommandExecutor.java:251)at java.util.Optional.orElseGet(Optional.java:267)at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:250)at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:41)at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)at io.appium.java_client.windows.WindowsDriver.execute(WindowsDriver.java:1)at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)at io.appium.java_client.AppiumDriver.startSession(AppiumDriver.java:336)at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:37)at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:88)at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:98)at io.appium.java_client.windows.WindowsDriver.<init>(WindowsDriver.java:42)at NotepadTest.setUp(NotepadTest.java:26)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:134)at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:63)at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:348)at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:302)at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:176)at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:122)at java.util.ArrayList.forEach(ArrayList.java:1249)at org.testng.TestRunner.privateRun(TestRunner.java:766)at org.testng.TestRunner.run(TestRunner.java:587)at org.testng.SuiteRunner.runTest(SuiteRunner.java:384)at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:378)at org.testng.SuiteRunner.privateRun(SuiteRunner.java:337)at org.testng.SuiteRunner.run(SuiteRunner.java:286)at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)at org.testng.TestNG.runSuitesSequentially(TestNG.java:1187)at org.testng.TestNG.runSuitesLocally(TestNG.java:1109)at org.testng.TestNG.runSuites(TestNG.java:1039)at org.testng.TestNG.run(TestNG.java:1007)at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)
Caused by: java.net.ConnectException: Connection refused: connectat java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)at java.net.Socket.connect(Socket.java:589)

参考

  1. https://github.com/microsoft/WinAppDriver
  2. https://github.com/microsoft/WinAppDriver/blob/master/Samples/Java/CalculatorTest/src/test/java/CalculatorTest.java
  3. https://github.com/Microsoft/WinAppDriver/releases
  4. https://medium.com/software-testing-break-and-improve/tutorial-windows-app-automation-using-winappdriver-and-java-5be661335b25
  5. https://medium.com/software-testing-break-and-improve/tutorial-windows-app-automation-using-winappdriver-and-java-5be661335b25
  6. https://mvnrepository.com/artifact/io.appium/java-client/7.3.0

WinAppDriver Test Example相关推荐

  1. element ui 获取文件的路径_win10使用WinAppDriver实现UI自动化

    win10使用WinAppDriver实现UI自动化 WinAppDriver说明 WinAppDriver(Windows Application Driver)是一个类似Selenium的UI自动 ...

  2. 基于Appium+WinAppDriver+Python的winUI3应用的自动化框架搭建分享(一)环境配置

    安装WinAppDriver 下载并安装WinAppDriver:来源 https://github.com/Microsoft/WinAppDriver/releases 开启电脑的开发者模式 设置 ...

  3. WinAppDriver做PC客户端自动化

    WinAppDriver做PC客户端自动化 1.WinAppDriver介绍 我们平时网页自动化用到的技术一般是使用selenium,selenium在网页端功能十分强大,基本你能想到的操作都能做到, ...

  4. JAVA 使用WinAppDriver对PC桌面软件进行自动化测试

    一.前置条件 1. 准备工具 WinAppDriver.exe    支持桌面软件UI自动化测试的服务    https://github.com/Microsoft/WinAppDriver/rel ...

  5. 聊聊 PC 端自动化最佳方案 - WinAppDriver

    点击上方 "AirPython",选择 "加为星标" 第一时间关注 Python 原创干货! 1. 前言 大家好,我是安果! 一提到自动化,可能大家想到的是 A ...

  6. 桌面自动化winappdriver、uiautomation、win32、pyautogui...

    我的需求是不通过鼠标也能实现点击等操作 就像浏览器脚本一样  可以不用鼠标,可以在自动化脚本运行时我们能做其他的事,但是经过上时间的发掘,我没发现这些库能较好地实现这样的需求 winappdriver ...

  7. win10使用WinAppDriver实现UI自动化

    WinAppDriver说明 WinAppDriver(Windows Application Driver)是一个类似Selenium的UI自动化测试服务 系统要求: Windows10或Windo ...

  8. JAVA 使用WinAppDriver对QT桌面软件进行自动化测试

    JAVA 使用WinAppDriver对QT桌面软件进行自动化测试 一.前置条件 1. 准备工具 工具名称 描述 下载地址 WinAppDriver.exe 支持桌面软件UI自动化测试的服务 http ...

  9. 对Windows桌面应用程序进行UI自动化测试

    所谓UI自动化测试,就是模拟一个用户,对应用程序的UI进行操作,以完成特定场景的功能性集成测试. 要对Windows桌面应用程序进行UI自动化测试,目前可选的技术主要是两种:VS自带的CodedUI ...

最新文章

  1. freemarker内建函数介绍
  2. html 标签开发,前端开发入门之HTML基础标签一
  3. 《当代 95 后の北上广出逃计划》
  4. 腾讯云携手SENSORO,为城市安全保驾护航
  5. python语言自学-python语言学习笔记整理
  6. java的知识点45——CLOB 存储大量的文本数据与 BLOB 二进制大对象
  7. RxSwift之深入解析map操作符的底层实现
  8. SAP Business Technology Platform 上 Roles,Roles collection 和 Scopes 的关联关系
  9. 《Spring揭秘》——IOC梳理2(容器启动,bean生命周期)
  10. Java下List使用subList实现分页获取
  11. Jquery easyUI datagrid载入复杂JSON数据方法
  12. Asp.net页面传值
  13. java接口压力测试
  14. Android 不透明度 对应表
  15. 利用无障碍服务自动获取微信号
  16. ubuntu黑屏有声音
  17. 分享99个PHP源码,总有一款适合您
  18. 云服务器惠普版_惠普被评为中国私有云解决方案领导厂商
  19. 神舟gx8cp5s1uefi的win10和ubuntu18.04双系统删除ubuntu
  20. ctfshow 萌新22 (类似级客巅峰web4)

热门文章

  1. twemproxy配置详解
  2. LeCun指明下一代AI方向:自主机器智能
  3. 代码随想录训练营day59
  4. remove.bg - 自动抠图、一键去除图片背景的免费在线工具
  5. 大数据舆情监测分析工作如何有效做好的解决方案
  6. 视觉SLAM(一)——视觉SLAM框架
  7. python图片表格提取算法_python识别并提取表格中的文字--Apple的学习笔记
  8. JointJS动态流程图升级
  9. win10 怎么禁用win键盘
  10. Educational Codeforces Round 133 (Rated for Div. 2)(CD题解)