Java tutorial
//****************************************************************************** // // /* Copyright (c) 2016 Appium Committers. All rights reserved. Licensed to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ // //****************************************************************************** import org.junit.*; import org.openqa.selenium.WebDriver; 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.ios.IOSDriver; import org.openqa.selenium.remote.RemoteWebDriver; public class CalculatorTest { private static RemoteWebDriver CalculatorSession = null; private static WebElement CalculatorResult = null; @BeforeClass public static void setup() { try { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("app", "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App"); capabilities.setCapability("platformName", "Windows"); capabilities.setCapability("deviceName", "WindowsPC"); CalculatorSession = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); CalculatorSession.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS); CalculatorSession.findElementByXPath("//Button[starts-with(@Name, \"Menu\")]").click(); CalculatorSession.findElementByXPath("//ListItem[@Name=\"Standard Calculator\"]").click(); CalculatorSession.findElementByName("Clear").click(); CalculatorSession.findElementByName("Seven").click(); CalculatorResult = CalculatorSession.findElementByName("Display is 7 "); Assert.assertNotNull(CalculatorResult); } catch (Exception e) { e.printStackTrace(); } finally { } } @Before public void Clear() { CalculatorSession.findElementByName("Clear").click(); Assert.assertEquals("Display is 0 ", CalculatorResult.getText()); } @AfterClass public static void TearDown() { CalculatorResult = null; if (CalculatorSession != null) { CalculatorSession.quit(); } CalculatorSession = null; } @Test public void Addition() { CalculatorSession.findElementByName("One").click(); CalculatorSession.findElementByName("Plus").click(); CalculatorSession.findElementByName("Seven").click(); CalculatorSession.findElementByName("Equals").click(); Assert.assertEquals("Display is 8 ", CalculatorResult.getText()); } @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("Display is 8 ", CalculatorResult.getText()); } @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("Display is 8 ", CalculatorResult.getText()); } @Test public void Multiplication() { CalculatorSession.findElementByName("Nine").click(); CalculatorSession.findElementByName("Multiply by").click(); CalculatorSession.findElementByName("Nine").click(); CalculatorSession.findElementByName("Equals").click(); Assert.assertEquals("Display is 81 ", CalculatorResult.getText()); } @Test public void Subtraction() { CalculatorSession.findElementByName("Nine").click(); CalculatorSession.findElementByName("Minus").click(); CalculatorSession.findElementByName("One").click(); CalculatorSession.findElementByName("Equals").click(); Assert.assertEquals("Display is 8 ", CalculatorResult.getText()); } }