使用Selendroid选择模拟器

时间:2014-09-30 14:00:16

标签: android selenium automated-tests selendroid

我正在尝试在运行Selendroid时选择模拟器并找到此标志

-emulatorPort “指定开始运行模拟器的端口号。”

List of devices attached 
emulator-5554   device
emulator-5558   device

由于我有两个模拟器在运行,我想在运行测试时选择其中一个。因此我在启动selendroid时使用了标志

java -jar selendroid-standalone-0.11.0-with-dependencies.jar -app app.apk -emulatorPort 5554

我写的测试代码以

开头
SelendroidCapabilities capa = new SelendroidCapabilities("app.package.name:1.0);
capa.setCapability(SelendroidCapabilities.EMULATOR, true);

driver = new SelendroidDriver(capa);

但是现在我在运行测试时崩溃了

INFO: executing command: /Applications/Android/platform-tools/adb shell pm clear app.package.name
io.selendroid.exceptions.ShellCommandException: An error occured while executing shell command: /Applications/Android/platform-tools/adb shell pm clear app.package.name
    at io.selendroid.io.ShellCommand.exec(ShellCommand.java:49)
    at io.selendroid.android.impl.AbstractDevice.executeCommand(AbstractDevice.java:176)
    at io.selendroid.android.impl.AbstractDevice.executeCommand(AbstractDevice.java:171)
    at io.selendroid.android.impl.AbstractDevice.clearUserData(AbstractDevice.java:199)
    at io.selendroid.server.model.DeviceStore.release(DeviceStore.java:81)
    at io.selendroid.server.model.SelendroidStandaloneDriver.createNewTestSession(SelendroidStandaloneDriver.java:245)
    at io.selendroid.server.handler.CreateSessionHandler.handle(CreateSessionHandler.java:42)
    at io.selendroid.server.SelendroidServlet.handleRequest(SelendroidServlet.java:143)
    at io.selendroid.server.BaseServlet.handleHttpRequest(BaseServlet.java:67)
    at io.selendroid.server.http.ServerHandler.channelRead(ServerHandler.java:50)
    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.processSelectedKeysOptimized(NioEventLoop.java:468)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
    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:745)
Caused by: io.selendroid.exceptions.ShellCommandException: error: more than one device and emulator
error: more than one device and emulator

似乎id没有使用“-s emulator-5554”选择正确的模拟器,这是一个错误还是我完全误解了标志“-emulatorPort”。如果我关闭其中一个模拟器,一切正常。

或者我是否必须使用Selendroid Grid,对我想做的事情来说似乎有点过分。

2 个答案:

答案 0 :(得分:1)

正如emulatorPort标志的描述所说,它用于指定新生成的模拟器的端口,而不是从已经运行的模拟器中选择。要从已经运行的模拟器中进行选择,请使用类似

的内容
capa.setSerial("emulator-5554");

将5554替换为所需仿真器的端口号。

答案 1 :(得分:0)

在您的脚本中使用它:

DesiredCapabilities capa=DesiredCapabilities.android();
capa.setCapability(SelendroidCapabilities.EMULATOR, true);
capa.setCapability(SelendroidCapabilities.ANDROID_TARGET, DeviceTargetPlatform.ANDROID18);
SelendroidDriver driver = new SelendroidDriver(capa);