zoukankan      html  css  js  c++  java
  • appium小例子

    package com.saucelabs.appium;

    import java.io.File;
    import java.net.URL;
    import java.util.List;
    import org.junit.After;
    import org.junit.Before;
    import org.junit.Test;
    import org.openqa.selenium.By;
    import org.openqa.selenium.Capabilities;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.interactions.HasTouchScreen;
    import org.openqa.selenium.interactions.TouchScreen;
    import org.openqa.selenium.remote.CapabilityType;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.openqa.selenium.remote.RemoteTouchScreen;
    import org.openqa.selenium.remote.RemoteWebDriver;

    public class AndroidContactsTest {
        private WebDriver driver;

        @Before
        public void setUp() throws Exception {
            File classpathRoot = new File(System.getProperty("user.dir"));
            File appDir = new File(classpathRoot, "app");
            File app = new File(appDir, "ContactManager.apk");
            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability("device", "Android");    
            capabilities.setCapability("platformName", "Android");
            //虚拟机
            //capabilities.setCapability("deviceName","Android Emulator");
            //真机
            capabilities.setCapability("deviceName","Android");
            //测试机Android version
            capabilities.setCapability("platformVersion", "4.4");
            capabilities.setCapability(CapabilityType.PLATFORM, "WINDOWS");
            capabilities.setCapability("app", app.getAbsolutePath());
            capabilities.setCapability("appPackage", "com.example.android.contactmanager");
            capabilities.setCapability("appActivity", ".ContactManager");
            driver = new SwipeableWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
        }

        @After
        public void tearDown() throws Exception {
            driver.quit();
        }

        @Test
        public void addContact(){
            WebElement el = driver.findElement(By.name("Add Contact"));
            el.click();
            List<WebElement> textFieldsList = driver.findElements(By.tagName("textfield"));
            textFieldsList.get(0).sendKeys("Some Name");
            textFieldsList.get(2).sendKeys("Some@example.com");
            driver.findElement(By.name("Save")).click();
        }

        public class SwipeableWebDriver extends RemoteWebDriver implements HasTouchScreen {
            private RemoteTouchScreen touch;

            public SwipeableWebDriver(URL remoteAddress, Capabilities desiredCapabilities) {
                super(remoteAddress, desiredCapabilities);
                touch = new RemoteTouchScreen(getExecuteMethod());
            }

            public TouchScreen getTouch() {
                return touch;
            }
        }
    }

  • 相关阅读:
    C# Log4.Net日志组件的应用系列(二)
    C# Log4.Net日志组件的应用系列(一)
    使用TFS+GIT实现分布式项目管理
    动软代码生成器使用教程
    SVN使用教程
    windows系统重装流程
    使用纯真IP库获取用户端地理位置信息
    使用扩展方法重写.NET底层架构
    使用单例模式创建模型仓储层的唯一调用
    使用SQL Delta.v5.1.1.98.破解版同步数据结构
  • 原文地址:https://www.cnblogs.com/stay-sober/p/4432539.html
Copyright © 2011-2022 走看看