我按照官方的例子修改了一下代码,然后就一直运行出错:
代码:
import unittest
from selenium import webdriver
########################################################################
class FindElementTest(unittest.TestCase):
"""打开 apk 找到"""
#----------------------------------------------------------------------
def setUp(self):
""""""
desired_capabilities={'aut':'com.example.bebb:1.9.1'}
self.driver=webdriver.Remote(
desired_capabilities=desired_capabilities
)
self.driver.implicitly_wait(30)
#全局定义超时,处理find_element_by 等操作超时均为30s
#----------------------------------------------------------------------
def test_find_element_by_id(self):
""""""
self.driver.get('and-activity://com.example.bebb.PlashScreen')
#print '11'
self.assertTrue("and-activity://PlashScreen" in self.driver.current_url)
print self.driver.current_url
closeWebView=self.driver.find_element_by_class_name('android.widget.ImageView')
closeWebView.click
self.driver.tap([(200,50)],1)
#----------------------------------------------------------------------
def tearDown(self):
"""tearDown"""
self.driver.quit()
if __name__=="__main__":
unittest.main()
报错:
E
======================================================================
ERROR: test_find_element_by_id (__main__.FindElementTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "d:\python\py_workspace\selendroid\selendroid_ceb01.py", line 12, in setUp
desired_capabilities=desired_capabilities
File "D:\Program File\python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 73, in __init__
self.start_session(desired_capabilities, browser_profile)
File "D:\Program File\python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 121, in start_session
'desiredCapabilities': desired_capabilities,
File "D:\Program File\python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 173, in execute
self.error_handler.check_response(response)
File "D:\Program File\python\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 166, in check_response
raise exception_class(message, screen, stacktrace)
WebDriverException: Message: Error starting Selendroid session
io.selendroid.exceptions.SessionNotCreatedException: Error starting Selendroid session
at io.selendroid.server.model.SelendroidStandaloneDriver.createNewTestSession(SelendroidStandaloneDriver.java:277)
at io.selendroid.server.handler.CreateSessionHandler.handle(CreateSessionHandler.java:44)
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: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.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(Unknown Source)
Caused by: io.selendroid.exceptions.SessionNotCreatedException: The requested application under test is not configured in selendroid server.
at io.selendroid.server.model.SelendroidStandaloneDriver.getAndroidApp(SelendroidStandaloneDriver.java:361)
at io.selendroid.server.model.SelendroidStandaloneDriver.createNewTestSession(SelendroidStandaloneDriver.java:192)
... 25 more
----------------------------------------------------------------------
Ran 1 test in 4.537s
FAILED (errors=1)
我看的是说这部分不对:
self.driver=webdriver.Remote(
desired_capabilities=desired_capabilities
)
但是就是不知道为什么不对,我用原代码就可以通过,原代码里边测试的 apk 就是 selendroid-test-app-0.12.0.apk。