|
| 1 | +package com.saucelabs.appium; |
| 2 | + |
| 3 | +import io.appium.java_client.AppiumDriver; |
| 4 | +import io.appium.java_client.android.AndroidDriver; |
| 5 | +import org.junit.After; |
| 6 | +import org.junit.Before; |
| 7 | +import org.junit.Test; |
| 8 | +import org.openqa.selenium.Dimension; |
| 9 | +import org.openqa.selenium.Point; |
| 10 | +import org.openqa.selenium.WebElement; |
| 11 | +import org.openqa.selenium.remote.DesiredCapabilities; |
| 12 | + |
| 13 | +import java.io.File; |
| 14 | +import java.net.URL; |
| 15 | + |
| 16 | +/** |
| 17 | + * Created by saikrisv on 26/04/16. |
| 18 | + */ |
| 19 | +public class AndroidSlideTest { |
| 20 | + private AppiumDriver<WebElement> driver; |
| 21 | + |
| 22 | + @Before |
| 23 | + public void setUp() throws Exception { |
| 24 | + File classpathRoot = new File(System.getProperty("user.dir")); |
| 25 | + File appDir = new File(classpathRoot, "../../../apps/ApiDemos/bin"); |
| 26 | + File app = new File(appDir, "ApiDemos-debug.apk"); |
| 27 | + DesiredCapabilities capabilities = new DesiredCapabilities(); |
| 28 | + capabilities.setCapability("deviceName","Android Emulator"); |
| 29 | + capabilities.setCapability("platformVersion", "4.4"); |
| 30 | + capabilities.setCapability("app", app.getAbsolutePath()); |
| 31 | + capabilities.setCapability("appPackage", "io.appium.android.apis"); |
| 32 | + capabilities.setCapability("appActivity", ".ApiDemos"); |
| 33 | + driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); |
| 34 | + } |
| 35 | + |
| 36 | + @After |
| 37 | + public void tearDown() throws Exception { |
| 38 | + driver.quit(); |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + public void testSlider(){ |
| 43 | + driver.findElementByXPath(".//*[@text='Views']").click(); |
| 44 | + driver.scrollTo("Seek Bar").click(); |
| 45 | + |
| 46 | + WebElement slider = driver.findElementById("io.appium.android.apis:id/seek"); |
| 47 | + Point sliderLocation = getCenter(slider); |
| 48 | + driver.swipe(sliderLocation.getX(), sliderLocation.getY(), sliderLocation.getX()-100, sliderLocation.getY(), 7000); |
| 49 | + |
| 50 | + } |
| 51 | + |
| 52 | + private Point getCenter(WebElement element) { |
| 53 | + |
| 54 | + Point upperLeft = element.getLocation(); |
| 55 | + Dimension dimensions = element.getSize(); |
| 56 | + return new Point(upperLeft.getX() + dimensions.getWidth()/2, upperLeft.getY() + dimensions.getHeight()/2); |
| 57 | + } |
| 58 | +} |
0 commit comments