capabilities = {} # 测试平台,与测试设备名字,由于这里是真机,所以设备名字不生效 capabilities['platformName'] = 'Android' capabilities['deviceName'] = 'Android Emulator' # 安卓测试版本,真机这里也不生效 capabilities['platformVersion'] = '6.0' # 设置支持的编码,这样设置后可以输入中文 capabilities['unicodeKeyboard'] = 'True' capabilities['resetKeyboard'] = 'True' # 设置APP的主包名和入口类 capabilities['appPackage'] = 'com.example.android.contactmanager' capabilities[ 'app'] = "C:\Users\\77465\\eclipse-workspace\\appiumdemo\\apps\\ContactManager.apk" capabilities['appActivity'] = '.ContactManager' # 初始化 driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', capabilities) #发送一个JSON格式capabilities 给服务器暴露REST API _http://127.0.0.1:4723/wd/hub.返回session ID赋值给drive add = driver.find_element_by_name('Add Contact') # add.click() textFieldsList = driver.find_elements_by_class_name('android.widget.EditText') textFieldsList[0].send_keys('ccc') textFieldsList[1].send_keys('15684457157') textFieldsList[2].send_keys('*****@*****.**') driver.swipe(100, 500, 100, 100, 2) # driver.find_element_by_name('Save').click() driver.quit() print "finished" #Later function # self.wd.find_elements_by_android_uiautomator('new UiSelector().package("com.tcl.ota").text("LATER")').click()
#!/usr/bin/python #-*-coding:utf8-*- #美好生活从python开始! from appium import webdriver from time import sleep d = { "platformName": "Android", #设备的系统类型 "platformVersion": "5.1.1", #手机系统版本 "deviceName": "emulator-5554", #手机序列号 "appPackage": "com.tencent.mobileqq", #APP的包名 "appActivity": ".activity.SplashActivity", #活动名称 "noReset": "true" #是否重置应用程序状态 } dr = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_capabilities=d)
import time from appium import webdriver from appium.webdriver.common.touch_action import TouchAction from TestSuite.TestSuiteHelper import ElementFinder port = 'http://localhost:4723/wd/hub' driver = webdriver.Remote( command_executor=port, desired_capabilities={ 'automationName': 'UiAutomator2', 'deviceName': 'samsung SM-G390F', 'platformName': 'Android', 'app': 'C:/Users/ze0396/Desktop/AGTGA/APKS/ZaraHome.apk', 'autoGrantPermissions': 'true', 'appWaitActivity': '*.*', 'fullreset': 'false', 'noReset': 'true' }) time.sleep(2) time.sleep(2) el = ElementFinder(driver, 178, 160) el.click() el.send_keys( 'tltmruwrocmibcbrsnahofofizulfrdqxepfyzacorppcffeycbvypjouktgjfjmqdletknmhhrjjwszsibkyxlgoaystjlgqhuaxclgwcjfgwlgvp' ) driver.back() time.sleep(2) el = ElementFinder(driver, 616, 56) el.click()
"plartformVersion": "", "deviceName": "", #安装包放入SDK目录下,拖动到appt.exe #运行命令 C:\SDK\build-tools\29.0.0>aapt.exe dump badging 安装包拖动 "udid": device, #识别多台设备 "appPackage": "", "appActivity": "", #记录启动app的行为(跳过、版本升级) "noReset": True, #可输入中文 "unicodekeyboard": True, #切换appium输入法跟手机输入法 "resetkeyboard": True } #本地客户端连接 driver = webdriver.Remote("http://localhost:4723/wd/hub", cap) def get_size(): x = driver.get_window_size()['width'] y = driver.get_window_size()['height'] return (x, y) #点击操作,延迟2秒,用u工具抓取xpath信息 try: #如果出现这个 if WebDriverWait(driver, 2).until(lambda x: x.find_element_by_xpath("")): #就是执行这个 driver.find_element_by_xpath("").click() except:
from appium import webdriver from appium.webdriver.common.mobileby import MobileBy from appium.webdriver.common.touch_action import TouchAction caps = { "platformName": "Android", "deviceName": "emulator-5554", "appPackage": "com.xxzb.fenwoo", "appActivity": "com.xxzb.fenwoo.activity.addition.WelcomeActivity", # "automationName": "UiAutomator2", "noReset": False } # 初始化客户端 driver = webdriver.Remote( command_executor='http://127.0.0.1:4723/wd/hub', desired_capabilities=caps, ) # 定位到 activity driver.start_activity(app_package="com.xxzb.fenwoo", app_activity=".activity.user.CreateGesturePwdActivity") time.sleep(1) e = driver.find_element_by_id('com.xxzb.fenwoo:id/right_btn') e.click() ## 九宫格的绘制 time.sleep(2) e = driver.find_element_by_id("com.xxzb.fenwoo:id/gesturepwd_create_lockview") size = e.rect
# 实战 appium +夜神模拟器安装并启动淘宝, # 3.导入模块 from appium import webdriver import time desired_caps = {} desired_caps['platformName'] = 'Android' # android的apk还是IOS的ipa desired_caps['platformVersion'] = '7.1.2' # android系统的版本号 desired_caps['deviceName'] = '127.0.0.1:62001' # 手机设备名称,通过adb devices 查看 desired_caps['appPackage'] = 'com.taobao.taobao' # apk的包名 desired_caps[ 'appActivity'] = 'com.taobao.tao.welcome.Welcome' # apk的launcherActivity # desired_caps['unicodeKeyboard'] = True #使用unicodeKeyboard的编码方式来发送字符串 # desired_caps['resetKeyboard'] = True #将键盘给隐藏起来 driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) # 启动服务器地址,后面跟的是手机信息 # 休眠10秒等待页面加载完成 time.sleep(10) # 使用xpath 定位 ,获取步骤,看xpath.png # elemet=driver.find_element_by_xpath("//android.widget.FrameLayout[@content-desc='天猫超市']") # elemet.click(); # 可以定位多个,获取出来,然后遍历按钮,做相关操作 # driver.find_elements_by_xpath() # 层级实战 也是获取天猫超市,并且点击,层级有点深 id = driver.find_element_by_id("com.taobao.taobao:id/rv_main_container") e1 = id.find_elements_by_class_name("android.widget.FrameLayout") e2 = e1[0].find_elements_by_class_name("android.widget.FrameLayout") e3 = e2[3].find_elements_by_class_name("android.widget.LinearLayout") e4 = e3[0].find_elements_by_class_name( "android.support.v7.widget.RecyclerView")
def setUpClass(self): self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", mysteel_app) self.driver.implicitly_wait(10)
def setUp(self): desired_caps = desired_capabilities.get_desired_capabilities( 'UICatalog.app.zip') self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
def Initialisation_Driver(p_udid, p_systemPort, p_deviceName, p_version, p_os): desired_caps = {} desired_caps['automationName'] = 'UiAutomator2' desired_caps['platformName'] = p_os desired_caps['platformVersion'] = p_version desired_caps['deviceName'] = p_deviceName desired_caps['udid'] = p_udid desired_caps['noReset'] = 'true' desired_caps['systemPort'] = p_systemPort desired_caps['chromeDriverPort'] = p_systemPort desired_caps['appWaitDuration'] = 100000 desired_caps['newCommandTimeout'] = 0 desired_caps['wdaStartupRetries'] = 4 desired_caps['wdaStartupRetryInterval'] = 20000 desired_caps['uiautomator2ServerLaunchTimeout'] = 100000 desired_caps['uiautomator2ServerInstallTimeout'] = 100000 desired_caps['remoteAppsCacheLimit'] = 0 desired_caps['waitForQuiescence'] = 'false' desired_caps['appPackage'] = 'com.facebook.katana' desired_caps['appActivity'] = 'com.facebook.katana.LoginActivity' cpt_appium_start = 0 while True: try: driver = webdriver.Remote('http://*****:*****@phonebot.co : {ex}" ) print( f"{p_udid}|||We can't open Facebook. Please check if device is connected. Let's try again!" ) if cpt_appium_start > 3: print( "Error", "PhoneBot couldn't initialize the driver. Please contact [email protected]." ) return None time.sleep(random.uniform(2.5, 3.3))
def open_setting(self): self.driver2 = webdriver.Remote('http://localhost:4723/wd/hub', self.desired_caps) return self.driver2
""" import time import unittest from appium import webdriver desired_caps = { 'platformName': 'Android', # 平台名称 'platformVersion': '7.1.2', # 系统版本号 'deviceName': '127.0.0.1:62001', # 设备名称。如果是真机,在'设置->关于手机->设备名称'里查看 'appPackage': 'com.ss.android.ugc.aweme', # apk的包名 'appActivity': 'com.ss.android.ugc.aweme.splash.SplashActivity' # activity 名称 } driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps) # 连接Appium driver.implicitly_wait(8) # 点击同意 time.sleep(3) print('开始同意') driver.find_element_by_id('com.ss.android.ugc.aweme:id/b9m').click() # 向上滑动 window = driver.get_window_size() x0 = window['width'] * 0.8 # 起始x坐标 x1 = window['width'] * 0.2 # 终止x坐标 y = window['height'] * 0.5 # y坐标 for i in range(4): driver.swipe(x0, y, x1, y, 500) time.sleep(1) # window = self.driver.get_window_size()
def open_application(self, port): self.driver = webdriver.Remote( 'http://localhost:' + str(port) + '/wd/hub', self.desired_caps) return self.driver
def setUpClass(cls): cls.driver = webdriver.Remote(config.APPIUM_SERVER, config.DESIRED_CAPABILITIES) cls.wait = WebDriverWait(cls.driver, 10) cls.reg = RegistrationScreen(cls.wait, cls.driver)
from time import sleep
#!/usr/bin/python #-*- coding;utf-8 -*_ #Author:朱浩龙 #明明你也最爱我,没理由爱不到结果,只要你敢不懦弱,凭什么我们要错过 from appium import webdriver from time import sleep a = {} a['platformName'] = 'Android' a['deviceName'] = '127.0.0.1:62001' a['appPackage'] = 'com.baidu.input' a['appActivity'] = 'ImeAppMainActivity' driver = webdriver.Remote('http://localhost:4723/wd/hub', a) sleep(2) driver.find_element_by_id('com.baidu.input:id/setdefault').click() sleep(2) driver.find_element_by_class_name('android.widget.LinearLayout').click() driver.find_element_by_id('com.baidu.input:id/finishsetting').click() sleep(5) driver.quit()
def setUp(self): url = 'http://127.0.0.1:4723/wd/hub' desired_caps = {} self.driver = webdriver.Remote(url, desired_caps)
import unittest from appium import webdriver desired_caps = {} desired_caps['platformName'] = 'Android' desired_caps['platformVersion'] = '6.0' desired_caps['deviceName'] = 'Android Emulator' desired_caps['avd'] = "DemoNexus" desired_caps['avdLaunchTimeout'] = 150000 desired_caps['appPackage'] = "com.android.calculator2" desired_caps['appActivity'] = "com.android.calculator2.Calculator" driver = webdriver.Remote( 'http://localhost:4723/wd/hub', desired_caps ) # passing the url of appium server, and the desired cap object driver.find_element_by_id("com.android.calculator2:id/digit_5").click() driver.find_element_by_id("com.android.calculator2:id/op_add").click() driver.find_element_by_id("com.android.calculator2:id/digit_6").click() driver.find_element_by_id("com.android.calculator2:id/eq").click() res = driver.find_element_by_id("com.android.calculator2:id/result").text print(res) if int(res) == 11: print("pass") else: print("fail")
def get(): caps = _capabilities[devices.PLATFORM] return appium_driver.Remote(command_executor=devices.APPIUM_SERVER, desired_capabilities=caps)
def appium_微信车站通_tmp(): desired_caps = {} with open(path_项目路径() + r'config\czt_wx.yaml', 'r', encoding='utf-8') as file: data = yaml.load(file, Loader=yaml.FullLoader) desired_caps['platformName'] = data['platformName'] desired_caps['platformVersion'] = data['platformVersion'] desired_caps['deviceName'] = data['deviceName'] desired_caps['udid'] = data['udid'] desired_caps['noReset'] = data['noReset'] # desired_caps['fullReset'] = data['fullReset'] desired_caps['unicodeKeyboard'] = data['unicodeKeyboard'] desired_caps['resetKeyboard'] = data['resetKeyboard'] desired_caps['appPackage'] = data['appPackage'] desired_caps['appActivity'] = data['appActivity'] desired_caps['automationName'] = data['automationName'] desired_caps['chromeOptions'] = data['chromeOptions'] logging.info('======启动微信======') driver = webdriver.Remote( 'http://' + str(data['ip']) + ':' + str(data['port']) + '/wd/hub', desired_caps) try: WebDriverWait( driver, 20).until(lambda x: x.find_element_by_android_uiautomator( 'new UiSelector().text("发现")')) except TimeoutException: logging.error("查找元素超时!") except NoSuchElementException: logging.error("微信登录后,标头元素找到不到!") else: sleep(1) logging.info("点击发现!") driver.find_element_by_android_uiautomator( 'new UiSelector().text("发现")').click() logging.info("点击小程序!") driver.find_element_by_android_uiautomator( 'new UiSelector().text("小程序")').click() logging.info("点击我的小程序!") driver.find_element_by_android_uiautomator( 'new UiSelector().text("我的小程序")').click() # driver.find_element_by_android_uiautomator('new UiSelector().text("开发版")').click() logging.info("点击车站通小程序!") driver.find_element_by_android_uiautomator( 'new UiSelector().text("车站通")').click() try: WebDriverWait(driver, 20).until( lambda x: x.find_element_by_id("com.tencent.mm:id/b1v")) except TimeoutException: logging.info("等待页面加载完毕\"车站头条\"") WebDriverWait( driver, 10).until(lambda x: x.find_element_by_android_uiautomator( 'new UiSelector().text("车站头条")')) except NoSuchElementException: logging.info("没有切换 站点提示!") logging.info("等待页面加载完毕\"车站头条\"") WebDriverWait( driver, 10).until(lambda x: x.find_element_by_android_uiautomator( 'new UiSelector().text("车站头条")')) return driver else: driver.find_element_by_id("com.tencent.mm:id/b1v").click() logging.info("等待页面加载完毕\"车站头条\"") WebDriverWait( driver, 10).until(lambda x: x.find_element_by_android_uiautomator( 'new UiSelector().text("车站头条")')) return driver
def driver(): """ 初始化driver, 在每个用例的setup()中创建实例 :return: """ return webdriver.Remote(Env.appium_url, Env.android_desc)
import sys importlib.reload(sys) #以下信息使用adb命令查看 desired_caps = {} desired_caps['platformName'] = 'Android' desired_caps['platformVersion'] = '7.0' desired_caps['deviceName'] = 'S9B7N17819001588' desired_caps['appPackage'] = 'com.android.contacts' #手机启动包名 desired_caps['appActivity'] = '.activities.PeopleActivity' #启动名 #以下两个变量,可以在输入框中输入中文 desired_caps['unicodeKeyboard'] = True desired_caps['resetKeyboard'] = True driver = webdriver.Remote('http://*****:*****@text,'新建联系人')]").click() time.sleep(2) name = [] for z in range(3): x = ran_letter() name.append(x)
#coding:utf-8 from appium import webdriver #导入driver对象 import base64 import time #声明手机驱动对象 #以下信息使用adb命令查看 desired_caps = {} desired_caps['platformName'] = 'Android' desired_caps['platformVersion'] = '8.1.0' desired_caps['deviceName'] = '4321ad89' desired_caps['appPackage'] = 'com.gamesci.u1.herou.prod' #手机启动包名 desired_caps['appActivity'] = 'com.gamesci.u1.UnityPlayerActivity' #启动名 #声明手机驱动对象 driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) #第一个服务端地址、第二个服务端启动参数 try: time.sleep(5) X = driver.get_window_size()['width'] Y = driver.get_window_size()['height'] print(X, Y) driver.tap(X * 0.5, Y * 0.5) time.sleep(50) except Exception as e: print(e) finally: driver.quit() #class name 不是唯一的,不能定位元素, #以下是元素定位方法
def setup_method(self) -> None: caps = get_desired_capabilities() caps['browserName'] = 'Chrome' self.driver = webdriver.Remote('http://localhost:4723/wd/hub', caps)
def setUp(self): device_configs = device.desired_caps self.driver = webdriver.Remote(device.appium_api_endpoint, device_configs)
from appium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC # appium服务监听地址 server='http://localhost:4723/wd/hub' # app启动参数 desired_caps={ "platformName": "Android", "deviceName": "vivo_X9", "appPackage": "com.tencent.mm", "appActivity": ".ui.LauncherUI" } # 驱动 driver = webdriver.Remote(server,desired_caps) wait = WebDriverWait(driver,30) # 获取登录按钮 login_btn = wait.until(EC.presence_of_element_located((By.ID,"com.tencent.mm:id/drp"))) # 点击登录按钮 login_btn.click() # 获取手机号文本框 phone_text = wait.until(EC.presence_of_element_located((By.ID,"com.tencent.mm:id/ji"))) # 填写手机号文本框 phone_text.send_keys("18888888888")
flag_auth = False print('\x1b[33mLogged on.\x1b[0m') f.write('Logged on.\n') return True return False desired_caps = {} desired_caps['deviceName'] = 'Emulator' desired_caps['platformVersion'] = '6.0' desired_caps['platformName'] = 'Android' desired_caps['exported'] = 'true' desired_caps['appPackage'] = 'ru.gigme.android.app' desired_caps['appActivity'] = '.MainActivity' wd = webdriver.Remote('http://127.0.0.1:5000/wd/hub', desired_caps) time.sleep(3) flag = False login = '******' passwd = 'nokiac60' if authorization(wd, 'an1lo', 'nokiac60') is False: flag = False else: time.sleep(1) if is_there_by_xpath(wd, u'//android.widget.TextView[@text=\'Настройки\']', False): wd.find_element_by_xpath( u'//android.widget.TextView[@text=\'Настройки\']').click() time.sleep(1)
import time,traceback desired_caps = {} desired_caps['platformName'] = 'Android' desired_caps['platformVersion'] = '5.1' desired_caps['deviceName'] = 'test' desired_caps['app'] = r'e:\apk\toutiao.apk' desired_caps['appPackage'] = 'io.manong.developerdaily' desired_caps['appActivity'] = 'io.toutiao.android.ui.activity.LaunchActivity' desired_caps['unicodeKeyboard'] = True desired_caps['noReset'] = True desired_caps['newCommandTimeout'] = 6000 #启动Remote RPC driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) driver.implicitly_wait(10) try: # ----------------- code = 'new UiSelector().resourceId("io.manong.developerdaily:id/tab_bar").childSelector(new UiSelector().className("android.widget.TextView").instance(3))' ele = driver.find_element_by_android_uiautomator(code) print ele.text ele.click() # ----------------- except: print traceback.format_exc()
def setUp(self): desired_caps = desired_capabilities.get_desired_capabilities('ApiDemos-debug.apk') self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
desired_caps["automationName"] = "UiAutomator2" # 平台类型 desired_caps["platformName"] = "Android" # 平台版本 desired_caps["platformVersion"] = "6.0.1" # 设备名称 desired_caps["deviceName"] = "Android Emulator" # app包名 desired_caps["appPackage"] = "cn.com.open.mooc" # app入口acitivity desired_caps[ "appActivity"] = "com.imooc.component.imoocmain.splash.MCSplashActivity" # 连接appium server。前提appium desktop要启动,有监听端口 # 要将desired_caps服务器参数发送给appium server,打开app driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) # 运行代码之前: # 1。appium server启动成功,处于监听状态 # 2。模拟器或者真机必须能够被电脑识别,即adb devices #点击同意 WebDriverWait(driver, 200).until( EC.visibility_of_element_located( (MobileBy.ID, "cn.com.open.mooc:id/btPositive"))) driver.find_element_by_id("cn.com.open.mooc:id/btPositive").click() # 点击左上角关闭 WebDriverWait(driver, 200).until( EC.visibility_of_element_located( (MobileBy.ID, "cn.com.open.mooc:id/left_icon"))) driver.find_element_by_id("cn.com.open.mooc:id/left_icon").click()
def setUp(self): '''测试准备工作''' # appium & 启动app/activity self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)