未在应用中捕获Webview

时间:2015-10-08 10:12:03

标签: android selenium selenium-webdriver appium

我在应用中有webview。我想得到它。所以我做了这样的事情:

public class AndroidSetup {
     protected AndroidDriver driver;
     protected void prepareAndroidForAppium() throws MalformedURLException {
        File appDir = new File("/Users/leonard/AmazonMobile/apps");
        File app = new File(appDir, "Amazon_App.apk");
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("deviceName","Android");
        capabilities.setCapability("platformName","Android");
        capabilities.setCapability("device", "selendroid");
        capabilities.setCapability("app", app.getAbsolutePath());
        driver =  new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    }
}

对于测试,我确实喜欢这个:

public class AppiumTest extends AndroidSetup {
    @BeforeClass
    public void setUp() throws Exception {
         prepareAndroidForAppium();
    }
    @Test
    public void falseLoginTest() throws InterruptedException
    {
        new LoginPage(driver).invalidLogin();
    }
}

LoginPage包含这样的函数:

public LoginPage invalidLogin() throws InterruptedException {
    WebDriverWait wait = new WebDriverWait(driver, 50);
    Set<String> contextNames = driver.getContextHandles();
    for (String contextName : contextNames) {
        System.out.println(contextName);
    }
    System.out.println("SIZE IS "+contextNames.size());
    return new LoginPage(driver);
}

仅在应用

中提供NATIVE_VIEW而非WEBVIEW

我的pom.xml看起来有这些依赖关系:

<dependencies>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.46.0</version>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.1.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.appium</groupId>
        <artifactId>java-client</artifactId>
        <version>3.0.0</version>
        <scope>test</scope>
    </dependency>
</dependencies>

0 个答案:

没有答案