AndroidDriver - Selenium库问题,无法读取AndroidManifest.xml错误(AndroidDriver - Selenium library issues and unable to read AndroidManifest.xml error)

我试图在Android模拟器(Mac)上运行https://code.google.com/p/selenium/wiki/AndroidDriver#Run_the_Tests上的示例测试,但在尝试运行测试时遇到问题。

我已经设置了一个模拟器并安装了WebDriver APK,然后在Eclipse中创建了一个新的Android应用程序项目,并创建了一个类OneTest.java并复制到代码中(也导入了org.openqa.selenium.WebDriver;示例代码)。 然后我将两个selenium-java-2.33.0罐子导入库中。 我还将我的androidmanifest更新为:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.test" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.test.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <uses-library android:name="android.test.runner" /> </application> <instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="com.example.test" /> </manifest>

当我尝试将OneTest.java作为Android Junit测试运行时,我看到错误:

[2013-07-25 11:53:36 - Test] The library 'selenium-java-2.33.0.jar' contains native libraries that will not run on the device. [2013-07-25 11:53:36 - Test] The following libraries were found: [2013-07-25 11:53:36 - Test] - org/openqa/selenium/firefox/amd64/libibushandler.so [2013-07-25 11:53:36 - Test] - org/openqa/selenium/firefox/amd64/x_ignore_nofocus.so [2013-07-25 11:53:36 - Test] - org/openqa/selenium/firefox/x86/libibushandler.so [2013-07-25 11:53:36 - Test] - org/openqa/selenium/firefox/x86/x_ignore_nofocus.so

如果我忽略错误并尝试再次运行它,我会看到:

[2013-07-25 11:59:43 - Test] Installing Test.apk... [2013-07-25 11:59:44 - Test] Installation failed due to invalid APK file! [2013-07-25 11:59:44 - Test] Please check logcat output for more details. [2013-07-25 11:59:44 - Test] Launch canceled!

在LogCat中:

07-25 10:59:44.188: D/zipro(23141): Zip: EOCD not found, /data/local/tmp/Test.apk is not zip 07-25 10:59:44.188: D/asset(23141): failed to open Zip archive '/data/local/tmp/Test.apk' 07-25 10:59:44.219: W/PackageParser(23141): Unable to read AndroidManifest.xml of /data/local/tmp/Test.apk 07-25 10:59:44.219: W/PackageParser(23141): java.io.FileNotFoundException: AndroidManifest.xml 07-25 10:59:44.219: W/PackageParser(23141): at android.content.res.AssetManager.openXmlAssetNative(Native Method) 07-25 10:59:44.219: W/PackageParser(23141): at android.content.res.AssetManager.openXmlBlockAsset(AssetManager.java:487) 07-25 10:59:44.219: W/PackageParser(23141): at android.content.res.AssetManager.openXmlResourceParser(AssetManager.java:455) 07-25 10:59:44.219: W/PackageParser(23141): at android.content.pm.PackageParser.parsePackageLite(PackageParser.java:733) 07-25 10:59:44.219: W/PackageParser(23141): at com.android.defcontainer.DefaultContainerService$1.getMinimalPackageInfo(DefaultContainerService.java:171) 07-25 10:59:44.219: W/PackageParser(23141): at com.android.internal.app.IMediaContainerService$Stub.onTransact(IMediaContainerService.java:110) 07-25 10:59:44.219: W/PackageParser(23141): at android.os.Binder.execTransact(Binder.java:351) 07-25 10:59:44.219: W/PackageParser(23141): at dalvik.system.NativeStart.run(Native Method) 07-25 10:59:44.219: W/DefContainer(23141): Failed to parse package

我确实试过这里的建议如何解决Selenium中的库问题? 改为使用android_webdriver_library.jar,但我在导入时遇到错误org.openqa.selenium.android.AndroidDriver; 和WebDriver driver = new AndroidDriver(); 我可以使用android.AndroidWebDriver来解决第一个问题。 但我无法解决AndroidDriver()的问题。

任何帮助都会很棒,因为我是Eclipse / Android noob :)

编辑:我通过添加以下进展:

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

到清单,但我看到错误“找不到类'org.openqa.selenium.android.AndroidDriver',从方法com.example.test.OneTest.testGoogle引用

I am trying to run the example test found here https://code.google.com/p/selenium/wiki/AndroidDriver#Run_the_Tests on an Android emulator (Mac), but I'm running into problems when trying to run the test.

I have set up an emulator and installed the WebDriver APK, then in Eclipse I created a new Android Application Project and created a class OneTest.java and copied in the code (also imported org.openqa.selenium.WebDriver; which was missing from the example code). Then I imported the two selenium-java-2.33.0 jars into the library. I also updated my androidmanifest to be:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.test" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.test.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <uses-library android:name="android.test.runner" /> </application> <instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="com.example.test" /> </manifest>

When I try to run OneTest.java as an Android Junit Test I see the error:

[2013-07-25 11:53:36 - Test] The library 'selenium-java-2.33.0.jar' contains native libraries that will not run on the device. [2013-07-25 11:53:36 - Test] The following libraries were found: [2013-07-25 11:53:36 - Test] - org/openqa/selenium/firefox/amd64/libibushandler.so [2013-07-25 11:53:36 - Test] - org/openqa/selenium/firefox/amd64/x_ignore_nofocus.so [2013-07-25 11:53:36 - Test] - org/openqa/selenium/firefox/x86/libibushandler.so [2013-07-25 11:53:36 - Test] - org/openqa/selenium/firefox/x86/x_ignore_nofocus.so

If I ignore the error and try to run it again I see:

[2013-07-25 11:59:43 - Test] Installing Test.apk... [2013-07-25 11:59:44 - Test] Installation failed due to invalid APK file! [2013-07-25 11:59:44 - Test] Please check logcat output for more details. [2013-07-25 11:59:44 - Test] Launch canceled!

And in LogCat:

07-25 10:59:44.188: D/zipro(23141): Zip: EOCD not found, /data/local/tmp/Test.apk is not zip 07-25 10:59:44.188: D/asset(23141): failed to open Zip archive '/data/local/tmp/Test.apk' 07-25 10:59:44.219: W/PackageParser(23141): Unable to read AndroidManifest.xml of /data/local/tmp/Test.apk 07-25 10:59:44.219: W/PackageParser(23141): java.io.FileNotFoundException: AndroidManifest.xml 07-25 10:59:44.219: W/PackageParser(23141): at android.content.res.AssetManager.openXmlAssetNative(Native Method) 07-25 10:59:44.219: W/PackageParser(23141): at android.content.res.AssetManager.openXmlBlockAsset(AssetManager.java:487) 07-25 10:59:44.219: W/PackageParser(23141): at android.content.res.AssetManager.openXmlResourceParser(AssetManager.java:455) 07-25 10:59:44.219: W/PackageParser(23141): at android.content.pm.PackageParser.parsePackageLite(PackageParser.java:733) 07-25 10:59:44.219: W/PackageParser(23141): at com.android.defcontainer.DefaultContainerService$1.getMinimalPackageInfo(DefaultContainerService.java:171) 07-25 10:59:44.219: W/PackageParser(23141): at com.android.internal.app.IMediaContainerService$Stub.onTransact(IMediaContainerService.java:110) 07-25 10:59:44.219: W/PackageParser(23141): at android.os.Binder.execTransact(Binder.java:351) 07-25 10:59:44.219: W/PackageParser(23141): at dalvik.system.NativeStart.run(Native Method) 07-25 10:59:44.219: W/DefContainer(23141): Failed to parse package

I did try the suggestion here How to solve library issue(s) in Selenium? to use android_webdriver_library.jar instead, but I got errors on import org.openqa.selenium.android.AndroidDriver; and WebDriver driver = new AndroidDriver(); I can resolve the first one by using android.AndroidWebDriver; but I can't resolve the issue with AndroidDriver().

Any help would be great since I'm an Eclipse/Android noob :)

Edit: I progressed a bit by adding:

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

to the manifest, but I see the error "Could not find class 'org.openqa.selenium.android.AndroidDriver', referenced from method com.example.test.OneTest.testGoogle

最满意答案

我通过创建Java项目解决了我的大多数问题,包括一个main方法并将其作为Java应用程序运行。 我还必须导入selenium-server-standalone-2.33.0.jar,否则在运行测试时会遇到错误。

I've solved most of my problems by creating a Java Project, including a main method and running this as a Java Application. I also had to import selenium-server-standalone-2.33.0.jar otherwise I'd run into an error when running the test.

更多推荐

android,java,电脑培训,计算机培训,IT培训"/> <meta name="description"