Last active
April 18, 2017 22:35
-
-
Save ootaken/11fefe2f7fa6907b3e3b4413fa1a585a to your computer and use it in GitHub Desktop.
Windows Application DriverでWindowsアプリケーションのテストを自動化しよう ref: http://qiita.com/ootaken/items/33099fcbd730e775e4db
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//****************************************************************************** | |
// | |
// 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 IN | |
// THE SOFTWARE. | |
// | |
//****************************************************************************** | |
import io.appium.java_client.windows.WindowsDriver; | |
import org.junit.*; | |
import org.openqa.selenium.WebElement; | |
import org.openqa.selenium.remote.DesiredCapabilities; | |
import java.util.concurrent.TimeUnit; | |
import java.net.URL; | |
import static org.hamcrest.CoreMatchers.containsString; | |
import static org.hamcrest.core.Is.is; | |
import static org.junit.Assert.assertThat; | |
public class CalculatorTest { | |
private static WindowsDriver calculatorSession = null; | |
private static WebElement calculatorResult = null; | |
@BeforeClass | |
public static void setup() throws Exception { | |
DesiredCapabilities capabilities = new DesiredCapabilities(); | |
capabilities.setCapability("app", "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App"); | |
calculatorSession = new WindowsDriver(new URL("http://127.0.0.1:4723"), capabilities); | |
calculatorSession.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS); | |
calculatorSession.findElementByAccessibilityId("clearButton").click(); | |
calculatorSession.findElementByAccessibilityId("num7Button").click(); | |
calculatorResult = calculatorSession.findElementByAccessibilityId("CalculatorResults"); | |
assertThat(calculatorResult, is(notNullValue())); | |
} | |
@Before | |
public void Clear() { | |
calculatorSession.findElementByAccessibilityId("clearButton").click(); | |
assertThat(calculatorResult.getText(), is(containsString(" 0 "))); | |
} | |
@AfterClass | |
public static void TearDown() { | |
calculatorResult = null; | |
if (calculatorSession != null) { | |
calculatorSession.quit(); | |
} | |
calculatorSession = null; | |
} | |
@Test | |
public void Addition() { | |
calculatorSession.findElementByAccessibilityId("num1Button").click(); | |
calculatorSession.findElementByAccessibilityId("plusButton").click(); | |
calculatorSession.findElementByAccessibilityId("num7Button").click(); | |
calculatorSession.findElementByAccessibilityId("equalButton").click(); | |
assertThat(calculatorResult.getText(), is(containsString(" 8 "))); | |
} | |
@Test | |
public void Combination() { | |
calculatorSession.findElementByAccessibilityId("num7Button").click(); | |
calculatorSession.findElementByAccessibilityId("multiplyButton").click(); | |
calculatorSession.findElementByAccessibilityId("num9Button").click(); | |
calculatorSession.findElementByAccessibilityId("plusButton").click(); | |
calculatorSession.findElementByAccessibilityId("num1Button").click(); | |
calculatorSession.findElementByAccessibilityId("equalButton").click(); | |
calculatorSession.findElementByAccessibilityId("divideButton").click(); | |
calculatorSession.findElementByAccessibilityId("num8Button").click(); | |
calculatorSession.findElementByAccessibilityId("equalButton").click(); | |
assertThat(calculatorResult.getText(), is(containsString(" 8 "))); | |
} | |
@Test | |
public void Division() { | |
calculatorSession.findElementByAccessibilityId("num8Button").click(); | |
calculatorSession.findElementByAccessibilityId("num8Button").click(); | |
calculatorSession.findElementByAccessibilityId("divideButton").click(); | |
calculatorSession.findElementByAccessibilityId("num1Button").click(); | |
calculatorSession.findElementByAccessibilityId("num1Button").click(); | |
calculatorSession.findElementByAccessibilityId("equalButton").click(); | |
assertThat(calculatorResult.getText(), is(containsString(" 8 "))); | |
} | |
@Test | |
public void Multiplication() { | |
calculatorSession.findElementByAccessibilityId("num9Button").click(); | |
calculatorSession.findElementByAccessibilityId("multiplyButton").click(); | |
calculatorSession.findElementByAccessibilityId("num9Button").click(); | |
calculatorSession.findElementByAccessibilityId("equalButton").click(); | |
assertThat(calculatorResult.getText(), is(containsString(" 81 "))); | |
} | |
@Test | |
public void Subtraction() { | |
calculatorSession.findElementByAccessibilityId("num9Button").click(); | |
calculatorSession.findElementByAccessibilityId("minusButton").click(); | |
calculatorSession.findElementByAccessibilityId("num1Button").click(); | |
calculatorSession.findElementByAccessibilityId("equalButton").click(); | |
assertThat(calculatorResult.getText(), is(containsString(" 8 "))); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> git clone https://github.com/Microsoft/WinAppDriver.git | |
> cd WinAppDriver\Samples\Java\CalculatorTest | |
> mvn test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Tests run: 5, Failures: 0, Errors: 5, Skipped: 0 | |
[INFO] ------------------------------------------------------------------------ | |
[INFO] BUILD FAILURE | |
[INFO] ------------------------------------------------------------------------ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> mvn test | |
Tests run: 5, Failures: 0, Errors: 0, Skipped: 0 | |
[INFO] ------------------------------------------------------------------------ | |
[INFO] BUILD SUCCESS | |
[INFO] ------------------------------------------------------------------------ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>CalculatorTest</groupId> | |
<artifactId>CalculatorTest</artifactId> | |
<version>1.0-SNAPSHOT</version> | |
<properties> | |
<java.version>1.8</java.version> | |
<maven.compiler.target>${java.version}</maven.compiler.target> | |
<maven.compiler.source>${java.version}</maven.compiler.source> | |
</properties> | |
<dependencies> | |
<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-BETA7</version> | |
</dependency> | |
</dependencies> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment