Reputation: 321
I am trying to select emulator when running Selendroid and found this flag
-emulatorPort "Specify the port number to start running emulators on."
List of devices attached
emulator-5554 device
emulator-5558 device
Since I have two emulators running I would like to choose one or the other when running my tests. I therefore use the flag when starting up selendroid
java -jar selendroid-standalone-0.11.0-with-dependencies.jar -app app.apk -emulatorPort 5554
The test code that I've written starts with this
SelendroidCapabilities capa = new SelendroidCapabilities("app.package.name:1.0);
capa.setCapability(SelendroidCapabilities.EMULATOR, true);
driver = new SelendroidDriver(capa);
But now it crashes when I run my test
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
Seems like id does not select the correct emulator using "-s emulator-5554", is this a bug or have I completely misunderstood the flag "-emulatorPort". If I close one of the emulators everything works fine.
Or do I have to use Selendroid Grid, just seems like such an overkill for what I am trying to do.
Upvotes: 0
Views: 1821
Reputation: 128
Use this in your script:
DesiredCapabilities capa=DesiredCapabilities.android();
capa.setCapability(SelendroidCapabilities.EMULATOR, true);
capa.setCapability(SelendroidCapabilities.ANDROID_TARGET, DeviceTargetPlatform.ANDROID18);
SelendroidDriver driver = new SelendroidDriver(capa);
Upvotes: 0
Reputation: 2803
As the description of the emulatorPort flag says it used to specify the port of a newly spawned emulator, not to choose from already running emulators. To choose from already running emulators use something like
capa.setSerial("emulator-5554");
replacing 5554 with the port number of the desired emulator.
Upvotes: 1