1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | # /usr/bin/python # -*- coding:utf8 -*- import unittest import time from appium import webdriver class MyTestCase(unittest.TestCase): def setUp( self ): self .desired_caps = {} self .desired_caps[ 'platformName' ] = 'Android' self .desired_caps[ 'platformVersion' ] = '6.0' self .desired_caps[ 'deviceName' ] = '192.168.135.101:5555' self .desired_caps[ 'appPackage' ] = 'mark.via' self .desired_caps[ 'appActivity' ] = 'mark.via.ui.activity.BrowserActivity' self .desired_caps[ 'unicodeKeyboard' ] = 'True' self .desired_caps[ 'resetKeybboard' ] = 'True' self .desired_caps[ 'automationName' ] = 'Selendroid' self .driver = webdriver.Remote( 'http://127.0.0.1:4723/wd/hub' , self .desired_caps) def testSearch( self ): # 进入baidu.com主页 self .driver.find_element_by_id( 'b0' ).click() self .driver.find_element_by_id( 'b0' ).send_keys( 'baidu.com' ) self .driver.find_element_by_id( 'b3' ).click() time.sleep( 5 ) # switch 切换当前的上下文 print ( self .driver.contexts) # contexts包含了native和webview两部分 # 切换到webview部分 #self.driver.switch_to.context('WEBVIEW_mark.via') #print(self.driver.current_context) time.sleep( 5 ) def tearDown( self ): self .driver.quit() if __name__ = = '__main__' : unittest.main() |
Appium中已配好application path,automation name也已设为为selendroid;
Appium版本为:AppiumForWindows_1_4_16_1
使用genymotion模拟器,采用6.0的系统,一直处于解锁状态
在Sublime Text3中直接运行脚本文件,Appium中提示以下错误: