Selendroid Python ActivityNotFound Exception

时间:2015-11-13 10:24:58

标签: python selenium android-activity selendroid

我正在学习如何使用selendroid在Python中自动化移动应用程序。

我关注了http://selendroid.io/mobileWeb.html,并成功地让移动网络模拟正常运行。

但是我在让原生应用示例工作http://selendroid.io/native.html时遇到了问题。

我的目标是能够测试Instagram应用程序。

这是我遵循的步骤:

  1. 我从中下载了instagram apk文件 http://www16.zippyshare.com/d/ItozZOlJ/28269/com.instagram.android-7.9.2-APK4Fun.com.apk并将其安装在BlueStacks模拟器上

  2. 接下来,我启动selenium独立服务器,将apk文件作为app参数

     java -jar selendroid-standalone-0.17.0-with-dependencies.jar -aut H:\PDS\andriod\com.instagram.android-7.9.2-APK4Fun.com.apk
    
  3. 要验证是否所有内容都已加载,我检查了链接http://localhost:4444/wd/hub/status并获得了:

    {
        status: 0,
        value: {
        supportedApps: [
            {
                appId: "io.selendroid.androiddriver:0.17.0",
                mainActivity: "io.selendroid.androiddriver.WebViewActivity",
                basePackage: "io.selendroid.androiddriver"
            },
            {
                appId: "com.instagram.android:7.9.2",
                mainActivity: "com.instagram.android.activity.MainTabActivity",
                basePackage: "com.instagram.android"
            }
        ],
        os: {
            arch: "amd64",
            name: "Windows 8.1",
            version: "6.3"
        },
        build: {
            browserName: "selendroid",
            version: "0.17.0"
        },
        supportedDevices: [
            {
                platformVersion: "23",
                emulator: true,
                apiTargetType: "google",
                avdName: "Nexus_5_API_23_x86"
            }
        ]
        }
    }
    

    这应该意味着一切都很好。我已经识别了我的设备,并且已经识别出MainActivity加载了apk文件。

  4. 现在我编写脚本以启动Instagram应用程序

    # initiate the driver
    driver = webdriver.Remote(desired_capabilities=webdriver.DesiredCapabilities.ANDROID)
    
    # switch to native app 
    driver.switch_to.window("NATIVE_APP")
    try:
        # try to start the MainTabActivity
        driver.get("and-activity://com.instagram.android.activity.MainTabActivity")
    finally:
        driver.quit()
    

    当我执行脚本时,我收到以下错误:

    Traceback (most recent call last):
      File "F:\Program Files (x86)\JetBrains\PyCharm 5.0\helpers\pydev\pydevd.py", line 2403, in <module>
        globals = debugger.run(setup['file'], None, None, is_module)
      File "F:\Program Files (x86)\JetBrains\PyCharm 5.0\helpers\pydev\pydevd.py", line 1794, in run
        launch(file, globals, locals)  # execute the script
      File "H:/PDS/BNP/bots/xexamples/connect_to_phone.py", line 12, in <module>
        driver.get("and-activity://com.instagram.android.activity.MainTabActivity")
      File "H:\program files\Anaconda\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 213, in get
        self.execute(Command.GET, {'url': url})
      File "H:\program files\Anaconda\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 201, in execute
        self.error_handler.check_response(response)
      File "H:\program files\Anaconda\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 181, in check_response
        raise exception_class(message, screen, stacktrace)
    selenium.common.exceptions.WebDriverException: Message: CATCH_ALL: android.content.ActivityNotFoundException: Unable to find explicit activity class {io.selendroid.androiddriver/com.instagram.android.activity.MainTabActivity}; have you declared this activity in your AndroidManifest.xml?
        at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1723)
        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1511)
        at android.app.ContextImpl.startActivity(ContextImpl.java:1039)
        at android.app.ContextImpl.startActivity(ContextImpl.java:1021)
        at io.selendroid.server.ServerInstrumentation.startActivity(ServerInstrumentation.java:77)
        at io.selendroid.server.model.SelendroidNativeDriver.get(SelendroidNativeDriver.java:115)
        at io.selendroid.server.model.DefaultSelendroidDriver.get(DefaultSelendroidDriver.java:522)
        at io.selendroid.server.handler.OpenUrl.safeHandle(OpenUrl.java:38)
        at io.selendroid.server.handler.SafeRequestHandler.handle(SafeRequestHandler.java:86)
        at io.selendroid.server.AndroidServlet.handleRequest(AndroidServlet.java:264)
        at io.selendroid.server.common.BaseServlet.handleHttpRequest(BaseServlet.java:67)
        at io.selendroid.server.common.http.ServerHandler.channelRead(ServerHandler.java:53)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)
        at io.netty.handler.traffic.AbstractTrafficShapingHandler.channelRead(AbstractTrafficShapingHandler.java:223)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)
        at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:163)
        at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:148)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)
        at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:787)
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:125)
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysPlain(NioEventLoop.java:430)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:384)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
        at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
        at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)
        at java.lang.Thread.run(Thread.java:841)
    

    它抛出ActivityNotFoundException错误,并询问我是否在AndroidManifest.xml中声明了此活动

  5. 问题:

    • 如何检查AndroidManifest中是否声明了某些内容?
    • 如果没有声明某些内容,我该如何申报呢? (不应该安装应用程序自动将其放入Android Manifest?)
    • 我在脚本中做错了吗?
    • 可以使用bluestack以某种方式与问题相关吗?

1 个答案:

答案 0 :(得分:0)

  1. 您可以使用apktool查看AndroidManifest中的内容。主要活动也在selendroid服务器日志中指定,就在您启动它时。
  2. 如果您反编译应用程序,将其添加到AndroidManifest并将其编译回来,您可能会这样做。这可能对您没有帮助,因为即使您在清单中添加了新活动,您的应用也不会使用该活动,除非编写代码来执行此操作。
  3. 不是真的
  4. 据我所知,
  5. 我遇到了同样的问题

    问题可以在这里看到:

    Unable to find explicit activity class {io.selendroid.androiddriver/com.instagram.android.activity.MainTabActivity}; have you declared this activity in your AndroidManifest.xml?
    

    Selendroid尝试使用位于selenium服务器所拥有的默认应用程序中的活动,而不是使用 app 参数传递的活动。哪个是 io.selendroid.androiddriver 。可能是个错误

    寻找解决方案