• @lihuazhang 
    
    上次我发给你的代码,其实第二和第三个find是没有执行,第一个就点击错误。
    
    def test_test(self):
            print 'Start to record Launch time...'
            time.sleep(1)
            current_context = self.driver.contexts
            print current_context
            self.driver.find_element_by_class_name("android.widget.Button").click()
            self.driver.find_element_by_id("com.morningeast.layouttest:id/my_button").click()
    
    下面两行是指的同一个操作, 两个都不是click 按钮“Click me”, 而都是点击了那个红色的图标。
    
    self.driver.find_element_by_class_name("android.widget.Button").click()
    self.driver.find_element_by_id("com.morningeast.layouttest:id/my_button").click()
    
    

  • @lihuazhang , 请问帮忙指出错在哪些,非常感谢!
    
  • @lihuazhang 谢谢,邮件已经发送,请查收

  • #12 楼 @lihuazhang @chenhengjie123

    sorry, 又打扰你们了,我的问题还没有解决,不过好像我们使用的是 layout 不是标准的 floating action button
    请问可以给我一个邮箱什么的,我发一个简单的测试 app 给你们,帮忙看看可以吗?
    非常感谢

  • setup()

    def setUp(self):
    desired_caps = {}
    desired_caps['platformName'] = 'Android'
    desired_caps['platformVersion'] = '4.4.2'
    desired_caps['deviceName'] = '03xxxxxxxxxxxxxxx'
    desired_caps['appPackage'] = 'com.good.salesforce1'
    desired_caps['appActivity'] = '.LaunchActivity'
    self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

    Test code
    current_context = self.driver.contexts
    print current_context
    self.driver.switch_to.context('WEBVIEW_com.salesforce.samples.contactexplorer')
    print self.driver.current_context

    console log
    test_test (main.recordTheTimeDuringLaunch) ...
    Step1, unlock G4SF1
    Start to record Launch time...
    [u'NATIVE_APP']
    ERROR

    ======================================================================

    ERROR: test_test (main.recordTheTimeDuringLaunch)

    Traceback (most recent call last):
    File "C:\Users\xdai\Desktop\Pythonpractice\Testing\TC9_Record_Launch_Time\recordTheTimeDuringLaunch_Timer.py", line 62, in test_test
    self.driver.switch_to.context('WEBVIEW_com.salesforce.samples.contactexplorer')
    File "build\bdist.win32\egg\appium\webdriver\switch_to.py", line 31, in context
    self._driver.execute(MobileCommand.SWITCH_TO_CONTEXT, {'name': context_name})
    File "C:\Python27\lib\site-packages\selenium-2.47.1-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 196, in execute
    self.error_handler.check_response(response)
    File "build\bdist.win32\egg\appium\webdriver\errorhandler.py", line 27, in check_response
    raise NoSuchContextException(wde.msg, wde.screen, wde.stacktrace)
    NoSuchContextException: Message: No such context found.


    Ran 1 test in 50.064s

    FAILED (errors=1)

    appium log
    info: [debug] Device is at API Level 19
    info: [debug] executing cmd: D:\sw\Android\android-sdk\platform-tools\adb.exe -s 03xxxxxxxxxxxxxxx sh
    ell "am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n
    com.good.salesforce1/.LaunchActivity"
    info: [debug] Waiting for pkg "com.good.salesforce1" and activity ".LaunchActivity" to be focused
    info: [debug] Getting focused package and activity
    info: [debug] executing cmd: D:\sw\Android\android-sdk\platform-tools\adb.exe -s 03xxxxxxxxxxxxxxx sh
    ell "dumpsys window windows"
    info: [debug] executing cmd: D:\sw\Android\android-sdk\platform-tools\adb.exe -s 03xxxxxxxxxxxxxxx sh
    ell "getprop ro.build.version.release"
    info: [debug] Device is at release version 4.4.2
    info: [debug] Device launched! Ready for commands
    info: [debug] Setting command timeout to the default of 60 secs
    info: [debug] Appium session started with sessionId c3f08750-ed35-4cab-a2db-5d9c3d01aee1
    info: <-- POST /wd/hub/session 303 4748.721 ms - 74
    info: --> GET /wd/hub/session/c3f08750-ed35-4cab-a2db-5d9c3d01aee1 {}
    info: [debug] Responding to client with success: {"status":0,"value":{"platform":"LINUX","browserNam
    e":"Android","platformVersion":"4.4.2","webStorageEnabled":false,"takesScreenshot":true,"javascriptE
    nabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,
    "warnings":{},"desired":{"platformVersion":"4.4.2","deviceName":"03xxxxxxxxxxxxxxx","platformName":"A
    ndroid","appActivity":".LaunchActivity","appPackage":"com.good.salesforce1"},"deviceName":"03xxxxxxxxxxxxxxx","platformName":"Android","appActivity":".LaunchActivity","appPackage":"com.good.salesforce1
    "},"sessionId":"c3f08750-ed35-4cab-a2db-5d9c3d01aee1"}
    info: <-- GET /wd/hub/session/c3f08750-ed35-4cab-a2db-5d9c3d01aee1 200 4.553 ms - 605 {"status":0,"v
    alue":{"platform":"LINUX","browserName":"Android","platformVersion":"4.4.2","webStorageEnabled":fals
    e,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled"
    :true,"locationContextEnabled":false,"warnings":{},"desired":{"platformVersion":"4.4.2","deviceName"
    :"039512595f0f029f","platformName":"Android","appActivity":".LaunchActivity","appPackage":"com.good.
    salesforce1"},"deviceName":"03xxxxxxxxxxxxxxx","platformName":"Android","appActivity":".LaunchActivit
    y","appPackage":"com.good.salesforce1"},"sessionId":"c3f08750-ed35-4cab-a2db-5d9c3d01aee1"}
    info: --> GET /wd/hub/session/c3f08750-ed35-4cab-a2db-5d9c3d01aee1/contexts {}
    info: [debug] Getting a list of available webviews
    info: [debug] executing cmd: D:\sw\Android\android-sdk\platform-tools\adb.exe -s 039512595f0f029f sh
    ell "cat /proc/net/unix"
    info: [debug] Available contexts:
    info: [debug] []
    info: [debug] Available contexts: NATIVE_APP
    info: [debug] Responding to client with success: {"status":0,"value":["NATIVE_APP"],"sessionId":"c3f
    08750-ed35-4cab-a2db-5d9c3d01aee1"}
    info: <-- GET /wd/hub/session/c3f08750-ed35-4cab-a2db-5d9c3d01aee1/contexts 200 85.690 ms - 86 {"sta
    tus":0,"value":["NATIVE_APP"],"sessionId":"c3f08750-ed35-4cab-a2db-5d9c3d01aee1"}
    info: --> POST /wd/hub/session/c3f08750-ed35-4cab-a2db-5d9c3d01aee1/context {"sessionId":"c3f08750-e
    d35-4cab-a2db-5d9c3d01aee1","name":"WEBVIEW_com.salesforce.samples.contactexplorer"}
    info: [debug] Getting a list of available webviews
    info: [debug] executing cmd: D:\sw\Android\android-sdk\platform-tools\adb.exe -s 039512595f0f029f sh
    ell "cat /proc/net/unix"
    info: [debug] Available contexts: NATIVE_APP
    info: [debug] []
    info: [debug] Available contexts: NATIVE_APP
    info: [debug] Responding to client with error: {"status":35,"value":{"message":"No such context foun
    d.","origValue":"Context 'WEBVIEW_com.salesforce.samples.contactexplorer' does not exist"},"sessionI
    d":"c3f08750-ed35-4cab-a2db-5d9c3d01aee1"}
    info: <-- POST /wd/hub/session/c3f08750-ed35-4cab-a2db-5d9c3d01aee1/context 500 74.353 ms - 195
    info: --> DELETE /wd/hub/session/c3f08750-ed35-4cab-a2db-5d9c3d01aee1 {}
    info: Shutting down appium session
    info: [debug] Pressing the HOME button
    info: [debug] executing cmd: D:\sw\Android\android-sdk\platform-tools\adb.exe -s 03xxxxxxxxxxxxxxx sh
    ell "input keyevent 3"
    info: [debug] Stopping logcat capture
    info: [debug] Logcat terminated with code null, signal SIGTERM
    info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"shutdown"}
    info: [debug] [BOOTSTRAP] [debug] Got command of type SHUTDOWN
    info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":"OK, shutting down","status":0}
    info: [debug] [BOOTSTRAP] [debug] Closed client connection
    info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
    info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=.
    info: [debug] Sent shutdown command, waiting for UiAutomator to stop...
    info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
    info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
    info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstr
    ap
    info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
    info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 0
    info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
    info: [debug] [UIAUTOMATOR STDOUT] Test results for WatcherResultPrinter=.
    info: [debug] [UIAUTOMATOR STDOUT] Time: 46.615
    info: [debug] [UIAUTOMATOR STDOUT] OK (1 test)
    info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: -1
    info: [debug] UiAutomator shut down normally
    info: [debug] Cleaning up android objects
    info: [debug] Cleaning up appium session
    info: [debug] Responding to client with success: {"status":0,"value":null,"sessionId":"c3f08750-ed35
    -4cab-a2db-5d9c3d01aee1"}
    info: <-- DELETE /wd/hub/session/c3f08750-ed35-4cab-a2db-5d9c3d01aee1 200 1174.811 ms - 76 {"status"
    :0,"value":null,"sessionId":"c3f08750-ed35-4cab-a2db-5d9c3d01aee1"}

  • @chenhengjie123
    非常感谢!我也用的是 1.4.13.1, 真机是 LG G2(4.4.2), 奇怪,为什么我不行?难道我们的 app 有什么特别?还是我自己做的有问题

  • @lihuazhang 同样的 python 脚本,当把 floating action button 移除后得到的结果是

    [u'NATIVE_APP', u'WEBVIEW_com.contactexplorer']

  • 我是用 python 写的 code

    current_context = self.driver.contexts
    print current_context

    打印出来只有 [u"NATIVE_APP"]

  • @lihuazhang
    非常感谢你的回复,我想请问一个问题,如何判断 webview 是否能够访问?
    其次,我找开发把 floating action button 移除掉后,是可以切换到 webview 的

  • @seveniruby

    请问你们帮我看看上面的问题吗?