正在学习 appium 使用,测试 hubird 混合应用。
测试环境:
Appium Desktop: 1.7.1
三星盖世 S7, Android 6.0.1

代码如下:

class PhoneAndroidTests(unittest.TestCase):
    def setUp(self):
        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '6.0.1'
        desired_caps['deviceName'] = 'jantest'
        desired_caps['appPackage'] = 'com.android.contacts'
        desired_caps['appActivity'] = 'com.android.dialer.DialtactsActivity'
        desired_caps['unicodeKeyboard'] = 'True'
        desired_caps['resetKeyboard'] = 'True'

        self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

    def tearDown(self):
        self.driver.quit()

    def test_demo(self):
        el = self.driver.find_element_by_id("com.android.contacts:id/one")
        el.click()
        el = self.driver.find_element_by_id("com.android.contacts:id/zero")
        el.click()
        el = self.driver.find_element_by_id("com.android.contacts:id/zero")
        el.click()
        el = self.driver.find_element_by_id("com.android.contacts:id/eight")
        el.click()
        el = self.driver.find_element_by_id("com.android.contacts:id/six")
        el.click()

        el = self.driver.find_element_by_id("com.android.contacts:id/dialButton")
        el.click()
        sleep(10)

        el = self.driver.find_element_by_id("com.android.incallui:id/endCallButtonContainer")
        el.click()
        sleep(1)

        self.driver.start_activity("com.android.mms", "com.android.mms.ui.ConversationComposer")
        sleep(1)

        textfields = self.driver.find_elements_by_class_name("android.widget.EditText")
        textfields[0].send_keys("10086")
        textfields[1].send_keys("厉害了我的国")
        el = self.driver.find_element_by_id("com.android.mms:id/send_button")
        el.click();
        sleep(1)

        self.driver.start_activity("com.sec.android.app.sbrowser", "com.sec.android.app.sbrowser.SBrowserMainActivity")
        sleep(1)
        totalcontext = self.driver.contexts
        print(totalcontext)
        # contexts = self.driver.current_context
        # print("current context is " + contexts)
        context_name = 'WEBVIEW_sbrowser'
        self.driver.context(context_name)
        sleep(1)
        """
        el = self.driver.find_element_by_name("百度一下")
        el.click()"""

问题出在,当我 start_activity 调起浏览器后,获取到当前的 context 有 “NATIVE_APP” 和 “WEBVIEW_sbrowser”,然后我试图切换 context(self.driver.context(context_name))的时候报错:

Traceback (most recent call last):
File "D:\zst\appiumvenv\Scripts\helloworld.py", line 66, in test_demo
self.driver.context(context_name)
TypeError: 'str' object is not callable

可这个 str 有什么错误呢?


↙↙↙阅读原文可查看相关链接,并与作者交流