ANDROID webdriver的硒 [英] ANDROID webdriver with selenium

查看:228
本文介绍了ANDROID webdriver的硒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行了Android SDK中的Web driver.the code给出的样本测试项目为:

I am running the sample test project given in the android sdk for web driver.the code is:

package simple.app.test;

import android.test.ActivityInstrumentationTestCase2;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.android.AndroidWebDriver;

import simple.app.SimpleAppActivity;

public class SimpleGoogleTest extends ActivityInstrumentationTestCase2<SimpleAppActivity> {
    private WebDriver driver;
    private WebDriver googledriver;

    public SimpleGoogleTest() {
        super("simple.app", SimpleAppActivity.class);
    }

    @Override
    protected void setUp() throws Exception {
      driver = new AndroidWebDriver(getActivity());
    }

    @Override
    protected void tearDown() {
       driver.quit();
    }

    public void testGoogleWorks() throws Exception {
        driver.get("http://www.google.com");
        Thread.sleep(10000);
        WebElement searchBox = driver.findElement(By.name("q"));
        searchBox.sendKeys("Android Rocks!");
        searchBox.submit();
        String title = driver.getTitle();
        assertTrue("Got title: " + title, title.contains("Google"));
       assertTrue(driver.findElements(By.partialLinkText("Android")).size() > 1);
    }
}

我收到了以下问题:

I am getting the following issue:

  1. Android2.2的-NoSuchMethorError
  2. Android2.3.1进程崩溃。

请帮我解决这些问题。

推荐答案

NEHA,

首先第一件事情,你有没有阅读的Andr​​oid驱动程序相关的维基页面上硒项目? HTTP://$c$c.google.com/p/selenium/wiki / AndroidDriver

first things first, have you read the relevant wiki page for Android driver on the Selenium project? http://code.google.com/p/selenium/wiki/AndroidDriver

,因为它说,Android的webdriver的最后一个版本支持Android 2.2的发布2.16的APK的,的http://$c$c.google.com/p/selenium/downloads/detail?name=android-server-2.16.apk

As it says, the last version of Android WebDriver to support Android 2.2 is release 2.16 of the APK, http://code.google.com/p/selenium/downloads/detail?name=android-server-2.16.apk

如果您需要preFER使用Android驱动程序的最新版本,我建议您尝试使用较新版本的Andr​​oid。正如你可能知道,这很容易地创建一个新的模拟器,一个新的AVD,因为它们可以亦称。该AndroidDriver维基页面解释说,因为在2.3模拟器中的错误,webdriver的将不是它的工作。但是它的工作运行2.3(或更高版本)在真实设备上

If you would prefer to use the current versions of the Android driver I would recommend you try using newer versions of Android. As you may know, it's easy to create a new emulator, a new AVD as they're also known. The AndroidDriver wiki page explains that because of a bug in the 2.3 emulator, WebDriver will not work in it. However it will work on a real device running 2.3 (or higher)

接下来的事情是检查是否在AndroidManifest.xml中的 目标应用有上网权限。 [注:我有这个权限在AndroidManifest.xml中两个文件,​​一个为虚拟的目标应用程序,并为TestProject的是安全的,但在我的测试中,我发现了一个似乎无所谓是一个用于应用程序的]

The next thing to check is whether the AndroidManifest.xml for the target app has the Internet permission. [Note: I have this permission in both AndroidManifest.xml files, the one for the dummy target app and for the TestProject to be safe, however in my testing I found the one that seemed to matter was the one for the app.]

<uses-permission android:name="android.permission.INTERNET" />

AFAIK Android的例子的应用程序被称为SimpleApp。

AFAIK the Android example's app is called SimpleApp.

另一条建议就是,试图捕捉的HTML的WebView那的加载,一旦webdriver的曾试图让谷歌主页上的内容。这里有一个简单的方法来做到这一点,我已经添加了电话后,对现有driver.get(...)

Another tip is to try and capture the HTML for the contents of the WebView that's loaded once WebDriver has tried to get the google homepage. Here's a simplistic way to do this, I've added the call after the existing driver.get(...)

driver.get("http://www.google.com");
Log.i("WebDriverDemo", driver.getPageSource());

这是简单的,因为呼叫记录结果有多少可以写入日志的限制,所以大的HTML源代码可能会被截断。然而,在日志中的信息可能足以让你找出问题所在。

It's simplistic because the call to Log the results has a restriction on how much it can write to the log, so large HTML source may be truncated. However the information in the log may be enough for you to identify the problem.

如果你还停留一旦你要么使用Android的webdriver的2.16试图在2.2模拟器或Android-webdriver的在仿真器与Android的如4.x版以后的当前版本,或许你可以在这里添加堆栈跟踪。

If you're still stuck once you've either tried using 2.16 of Android-WebDriver in your 2.2 emulator, or the current version of Android-WebDriver in an emulator with a later of Android e.g 4.x, perhaps you could add the stack trace here.

好运气

朱利安。

PS:我用NEHA提供了类似的回答到并行较早前的问题。我建议NEHA更新,链接到这个新版本的问题。

这篇关于ANDROID webdriver的硒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆