示例#1
0
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '5.1'
desired_caps['deviceName'] = '192.168.56.101:5555'
# 输入中文
desired_caps['unicodeKeyboard'] = True
desired_caps['resetKeyboard'] = True
# app的信息
desired_caps['appPackage'] = 'com.android.settings'
desired_caps['appActivity'] = '.Settings'

# 声明我们的driver对象
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
"""
目标:move_to移动方法
需求:1.使用TouchAction类内方法
    2.从  存储   移动到   更多
    思路:1.首先点击存储别松手
        2.往更多方向移动
        3.移动到更多位置,松手
"""
# 定位wlan
save = driver.find_element_by_xpath("//*[@text='存储']")
more = driver.find_element_by_xpath("//*[@text='更多']")

# 单独测试按下
TouchAction(driver).press(save).wait(100).move_to(more).wait(
    100).release().perform()

sleep(2)
driver.quit()
示例#2
0
 def long_press(self, x, y):
     TouchAction(self.driver).long_press(x = x, y = y).perform()
示例#3
0
 def touch_action(self):
     return TouchAction(self.driver)
示例#4
0
# This sample code uses the Appium python client
# pip install Appium-Python-Client
# Then you can paste this into a file and simply run with Python

from appium import webdriver
# from appium import TouchAction
from appium.webdriver.common.touch_action import TouchAction

caps = {}
caps["platformVersion"] = "10.3.2"
caps["platformName"] = "iOS"
caps["deviceName"] = "PG-0130"
caps["automationName"] = "XCUITest"
caps["bundleId"] = "com.vstudio.camera360"
caps["udid"] = "b1c8e924eb629f79a34ca4a3b2b638ec70cdb7c0"

driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)

# TouchAction action = new TouchAction(driver)
TouchAction(driver).tap(x=70, y=514).perform()
TouchAction(driver).tap(x=235, y=543).perform()
TouchAction(driver).tap(x=79, y=112).perform()
TouchAction(driver).tap(x=38, y=136).perform()
TouchAction(driver).tap(x=158, y=538).perform()
TouchAction(driver).tap(x=37, y=509).perform()
TouchAction(driver).tap(x=167, y=458).perform()
TouchAction(driver).tap(x=289, y=546).perform()
TouchAction(driver).tap(x=286, y=18).perform()

driver.quit()
示例#5
0
 def test_touch_action(self):
     action = TouchAction(self.driver)
     width = self.driver.get_window_rect()['width']
     height = self.driver.get_window_rect()['height']
#!/usr/bin/python3  
# -*- coding: utf-8 -*-
# @File    : touch_action.py
# @Author  : BAOSHUNCHIN
# @Email   : [email protected]
# @Time    : 2020-12-13 10:23

from appium.webdriver.common.touch_action import TouchAction

TouchAction().press(x=120, y=650).wait(10).move_to(x=360, y=410).release().perform()
 def test_touchaction_1(self):
     print("解锁手势密码")
     TouchAction(self.driver).press(x=244, y=374).wait(100).move_to(
         x=711, y=374).wait(100).move_to(x=1198, y=384).wait(100).move_to(
             x=1198, y=1323).wait(100).release().perform()
示例#8
0
def search_plate(plate):
    wd = get_driver()

    # Touch vehicle search image button
    botoes = wd.find_element_by_id('botoes')
    TouchAction(wd).tap(x=400, y=500).perform()

    # Fill form and search for vehicle by plate
    wd.find_element_by_id('txPlacaLetra').send_keys(plate[:3])
    wd.find_element_by_id('txPlacaNumero').send_keys(plate[3:])
    wd.find_element_by_id('imgBtnConsultar').click()

    try:
        message = wd.find_element_by_id('message')
    except NoSuchElementException:
        message = None

    message = message and message.text
    if message and message.lower() == 'Veículo não encontrado':
        data = {
            'city': None,
            'state': None,
            'brand': None,
            'model': None,
            'year': None,
            'color': None,
            'municipio_uf': None,
            'chassis': None,
            'date': None,
            'return_code': 1,
            'return_message': message,
            'status_code': None,
            'status_message': None,
        }
        return data

    consulta = None
    start_time = int(time.time())
    while not consulta:
        end_time = int(time.time())
        if (end_time - start_time) > 30:
            print('Timeout')
            exit(1)

        try:
            consulta = wd.find_element_by_id('txDataHoraConsulta')
        except NoSuchElementException:
            pass

    try:
        situacao = wd.find_element_by_id('imgBtnSituacaoLegal')
    except NoSuchElementException:
        situacao = None

    marca_modelo = wd.find_element_by_id('txMarcaModelo').text
    munipicio_uf = wd.find_element_by_id('txMunicipioUF').text
    chassi = wd.find_element_by_id('txChassi').text
    data_hora = wd.find_element_by_id('txDataHoraConsulta').text

    city, state = munipicio_uf.split('/')
    brand_model, year, color = [x.strip() for x in marca_modelo.split('-')]
    brand = brand_model.split()[0]
    model = ' '.join(brand_model.split()[1:])
    chassis = '************' + chassi.split()[-1]
    date = data_hora.split()[-3] + ' ' + data_hora.split()[-1]
    status_code = 0 if situacao else 1
    status_message = 'Sem restrição' if situacao else 'Com restrição'

    data = {
        'city': city,
        'state': state,
        'brand': brand,
        'model': model,
        'year': year,
        'color': color,
        'municipio_uf': munipicio_uf,
        'chassis': chassis,
        'date': data_hora,
        'return_code': 0,
        'return_message': 'Sem erros.',
        'status_code': status_code,
        'status_message': status_message,
    }

    return data
示例#9
0
 def tap(self, el):
     action = TouchAction(self.driver)
     action.tap(el).perform()
示例#10
0
文件: base.py 项目: xiaoxiayu/XXUIA
 def long_press(self, start_x, start_y, duration):
     action = TouchAction(self.driver)
     action \
         .long_press(x=start_x, y=start_y, duration=duration)
     action.perform()
示例#11
0
desired_caps['appActivity'] = '.Settings'

#当输入中文时,需添加以下2个参数
desired_caps['unicodeKeyboard'] = True
desired_caps['reseKeyboard'] = True

#连接appium服务器,获取driver
driver = webdriver.Remote('http://*****:*****@text='WLAN']")
# print(button.location) #获取坐标

#TouchAction(driver).press(x=650,y=650).release().press(x=32,y=194).release().perform()

# TouchAction(driver).tap(x=144,y=304).perform() #点击进入
# time.sleep(2)
# TouchAction(driver).press(x=144,y=304).wait(2000).release().perform()  #wait等待2s,

#---------长按操作
TouchAction(driver).tap(x=144, y=304).perform()  #点击进入
time.sleep(2)
TouchAction(driver).long_press(x=144, y=304,
                               duration=2000).perform()  #duration持续时间

time.sleep(8)
driver.quit()
示例#12
0
    def test_001_jd_finance(self):
        '''京东金融签到/领取提额包'''
        #----------启动应用----------
        AppTask.basic('com.jd.jrapp', '.WelcomeActivity')

        #----------九宫格滑动解锁----------
        TouchAction(driver).press(x=180, y=598).move_to(
            x=0, y=0).wait(100).move_to(x=0, y=181).wait(100).move_to(
                x=0, y=181).wait(100).move_to(x=181, y=0).wait(100).move_to(
                    x=181, y=0).release().perform()
        time.sleep(2)
        #这里重点注意,x,y的值是偏移量,不是坐标,参考https://testerhome.com/topics/9698

        # ----------检验是否有更新----------
        update = driver.page_source.find('跳过')  #判断是否有更新按钮
        if update != -1:
            driver.find_element_by_id(
                'com.jd.jrapp:id/cancel').click()  #点击"跳过",不更新
            time.sleep(1)
        else:
            pass

        #----------领取白条提额包----------
        cancel1 = driver.page_source.find(
            'com.jd.jrapp:id/ibtn_zc_product_notice_board_close'
        )  #判断进入首页时是否有消息弹窗
        if cancel1 != -1:
            driver.find_element_by_id(
                'com.jd.jrapp:id/ibtn_zc_product_notice_board_close').click(
                )  # 点击关闭弹窗
            print('进入首页时的弹窗已关闭')
            driver.find_elements_by_id(
                'com.jd.jrapp:id/tv_tab_strip')[1].click()  #点击顶部白条按钮
            time.sleep(1)
            #这里再做一次弹窗的判断,使用过程中发现这里也有弹窗
            cancel1 = driver.page_source.find(
                'com.jd.jrapp:id/ibtn_zc_product_notice_board_close')
            if cancel1 == -1:
                driver.find_element_by_id(
                    'com.jd.jrapp:id/tv_mid_text').click()  #点击白条资产卡片
                time.sleep(1)
            else:
                driver.find_element_by_id(
                    'com.jd.jrapp:id/ibtn_zc_product_notice_board_close'
                ).click()  # 点击关闭弹窗
                driver.find_element_by_id(
                    'com.jd.jrapp:id/tv_mid_text').click()  # 点击白条资产卡片
                time.sleep(1)
        else:
            driver.find_elements_by_id(
                'com.jd.jrapp:id/tv_tab_strip')[1].click()  # 点击顶部白条按钮
            time.sleep(1)
            cancel1 = driver.page_source.find(
                'com.jd.jrapp:id/ibtn_zc_product_notice_board_close')
            if cancel1 == -1:
                driver.find_element_by_id(
                    'com.jd.jrapp:id/tv_mid_text').click()  #点击白条资产卡片
                time.sleep(3)
            else:
                driver.find_element_by_id(
                    'com.jd.jrapp:id/ibtn_zc_product_notice_board_close'
                ).click()  # 点击关闭弹窗
                driver.find_element_by_id(
                    'com.jd.jrapp:id/tv_mid_text').click()  # 点击白条资产卡片
                time.sleep(3)

        ti_button = driver.page_source.find('1个提额包')  #判断是否有"1个提额包"的按钮
        if ti_button != -1:  #如果不等于-1则证明提额的按钮存在,否则这里是"额度管理"的按钮
            time.sleep(1)
            driver.find_element_by_id(
                'com.jd.jrapp:id/tv_right_oval_tips').click()  #点击"1个提额包"按钮
            time.sleep(10)
            driver.swipe(640, 430, 640, 430, 10)  #点击"提额"按钮
            time.sleep(1)
            driver.get_screenshot_as_file(screenshot_path +
                                          '京东金融提额包.jpg')  #提额完成后截图保存
            print('提额完成')
            driver.find_element_by_id(
                'com.jd.jrapp:id/btn_left').click()  #点击左上角的"X"返回上一步
            driver.keyevent(
                4
            )  # appium模拟手机按钮的方法,这里是模拟返回键继续返回上一步,详见:http://www.cnblogs.com/jiuyigirl/p/7126753.html
        else:
            time.sleep(3)
            driver.get_screenshot_as_file(screenshot_path +
                                          '京东金融提额包.jpg')  # 提额完成后截图保存
            print('本周已经领取过提额包,下周再来')
            pass
            driver.keyevent(4)
        time.sleep(1)

        #----------个人中心签到----------
        driver.find_element_by_id(
            'com.jd.jrapp:id/fourthLayout').click()  #点击个人中心
        time.sleep(1)
        driver.find_elements_by_id(
            'com.jd.jrapp:id/tv_item_label')[0].click()  #获取这一类标签,签到是第一个,并点击签到
        time.sleep(20)

        driver.swipe(600, 410, 600, 410, 10)  # 点击"签到领钢镚"按钮
        time.sleep(1)
        driver.get_screenshot_as_file(screenshot_path +
                                      '京东金融签到.jpg')  # 签到完成后截图保存
        driver.find_element_by_id(
            'com.jd.jrapp:id/common_webview_navbar_left').click()
        time.sleep(1)
        print('今日签到完成')
        self.assertIn('已签',
                      driver.page_source,
                      msg='任务有失败,请到截图目录查看截图' + str(screenshot_path))
示例#13
0
    "appPackage":
    "com.promytheus.findmytalent",
    "appActivity":
    "com.promytheus.findmytalent.SplashActivity",
    "appWaitActivity":
    "com.promytheus.findmytalent.MainActivity",
    "app":
    "C:\\Users\\priya\\QA\\MobileAutomation_Project\\findmytalent-prodapp-release.apk"
}

driver = webdriver.Remote("http://localhost:4723/wd/hub", desired_capabilites)

# choose "" option from the questions listed in find my talent page

driver.implicitly_wait(3)
driver.find_element_by_xpath(Locators.page1_Qtn2_xpath).click()
driver.implicitly_wait(3)
scroll = TouchAction(driver)
scroll.press(x=485, y=1731).move_to(x=485, y=337).release().perform()
driver.implicitly_wait(3)
driver.find_element_by_xpath(Locators.page1_Next_xpath).click()
driver.implicitly_wait(3)
driver.find_element_by_xpath(Locators.page2_Qtn2_xpath).click()
driver.implicitly_wait(3)
driver.find_element_by_xpath(Locators.page2_Next_xpath).click()
driver.implicitly_wait(3)
driver.find_element_by_xpath(Locators.page3_Qtn1_xpath).click()
driver.implicitly_wait(3)
driver.find_element_by_xpath(Locators.page3_Next_xpath).click()
driver.implicitly_wait(3)
 def long_press(self, locator, duration=1000):
     """ Long press the element with optional duration """
     driver = self._current_application()
     element = self._element_find(locator, True, True)
     action = TouchAction(driver)
     action.press(element).wait(duration).release().perform()
 def click_element_at_coordinates(self, coordinate_X, coordinate_Y):
     """ click element at a certain coordinate """
     self._info("Pressing at (%s, %s)." % (coordinate_X, coordinate_Y))
     driver = self._current_application()
     action = TouchAction(driver)
     action.press(x=coordinate_X, y=coordinate_Y).release().perform()
示例#16
0
文件: base.py 项目: xiaoxiayu/XXUIA
 def tem0(self, x):
     print(x)
     action = TouchAction(self.driver)
     action \
         .long_press(x=100, y=100, duration=1000)
 def __init__(self, driver):
     self.driver = driver
     self.driver.set_explicit(self.EXPLICIT_WAIT_TIME)
     self.action = TouchAction(self.driver)
示例#18
0
 def drag_and_drop(self, ele1, ele2):
     """长按元素ele1并将ele1拖动至ele2"""
     touch = TouchAction(driver)
     touch.long_press(ele1).wait(1000).move_to(ele2).wait(
         1000).release().perform()
示例#19
0
    def test_TaCenter(self):
        time.sleep(5)
        try:
            #进入个人中心
            PersonCenter = self.driver.find_element_by_id('com.ccvideo:id/tab_bar_mine_btn')
            PersonCenter.click()
            time.sleep(2)
            #进入粉丝列表
            self.driver.find_element_by_id('com.ccvideo:id/fans_count_tv').click()
            time.sleep(2)
            #进入他人个人中心
            self.driver.find_element_by_id('com.ccvideo:id/title_layout').click()
            time.sleep(2)
            #改变关注状态
            self.driver.find_element_by_id('com.ccvideo:id/operation_action_iv').click()
            #修改备注
            self.driver.find_element_by_id('com.ccvideo:id/mine_set_remarks_tv').click()
            remark = self.driver.find_element_by_id('com.ccvideo:id/remark_remarks_et')
            remark.click()
            remark.send_keys("哼哼哈嘿")
            self.driver.find_element_by_id('com.ccvideo:id/menu_commit').click()
            #观看视频
            self.driver.find_element_by_id('com.ccvideo:id/mv_video_logo_iv').click()
            self.driver.back()
            #粉丝列表
            self.driver.find_element_by_id('com.ccvideo:id/fans_count_tv').click()
            self.driver.back()
            #关注列表
            self.driver.find_element_by_id('com.ccvideo:id/follow_count_tv').click()
            self.driver.back()
            #私信
            self.driver.find_element_by_xpath("//android.widget.TextView[contains(@text,'私信')]").click()
            time.sleep(2)
            #发送评论
            mes = self.driver.find_element_by_id('com.ccvideo:id/et_sendmessage')
            mes.click()
            mes.send_keys("哦四季度卡i温暖的考虑为")
            self.driver.find_element_by_name("发送").click()
            #发送语音
            self.driver.find_element_by_id('com.ccvideo:id/btn_set_mode_voice').click()
            voice = self.driver.find_element_by_name("按住说话")
            action1 = TouchAction(self.driver)
            action1.long_press(voice).wait(4000).perform()
            time.sleep(2)
            #选择更多
            self.driver.find_element_by_id('com.ccvideo:id/btn_more').click()
            #发送视频
            self.driver.find_element_by_id('com.ccvideo:id/btn_video').click()
            time.sleep(3)
            #设置分类
            self.driver.find_element_by_xpath("//android.widget.TextView[contains(@text,'#颜控#')]").click()
            #切换音频
            self.driver.find_element_by_id('com.ccvideo:id/live_pre_live_mode').click()
            #切换视频
            self.driver.find_element_by_id('com.ccvideo:id/live_pre_live_mode').click()
            #旋转镜头
            self.driver.find_element_by_id('com.ccvideo:id/live_cover_tv').click()
            self.driver.find_element_by_name("拍照").click()
            self.driver.find_element_by_id('com.ccvideo:id/live_set_thumb_camera_cb').click()
            time.sleep(2)
            self.driver.find_element_by_id('com.ccvideo:id/live_ready_shoot_thumb_btn').click()
            #开始直播
            self.driver.find_element_by_id('com.ccvideo:id/live_start_btn').click()
            #更多设置
            self.driver.find_element_by_id('com.ccvideo:id/live_options_right_arrow_iv').click()
            #修改标题
            self.driver.find_element_by_name("标题").click()
            title = self.driver.find_element_by_class_name('android.widget.EditText')
            title.click()
            title.send_keys("heihei")
            self.driver.find_element_by_name("确定").click()
            #修改分类
            self.driver.find_element_by_name("分类").click()
            self.driver.find_element_by_name("陪我").click()
            #静音
            self.driver.find_element_by_id('com.ccvideo:id/live_mute_cb').click()

            self.driver.find_element_by_id('com.ccvideo:id/live_options_left_arrow_iv').click()
            #评论
            self.driver.find_element_by_id('com.ccvideo:id/live_comment_iv').click()
            self.driver.find_element_by_id('com.ccvideo:id/rl_input').send_keys("heihei")
            self.driver.find_element_by_name("发送").click()
            #分享
            self.driver.find_element_by_id('com.ccvideo:id/live_share_iv').click()
            self.driver.back()
            #关闭直播
            self.driver.find_element_by_id('com.ccvideo:id/live_close_iv').click()
            self.driver.find_element_by_name("确定").click()
            #回放
            self.driver.find_element_by_id('com.ccvideo:id/lep_left_tv').click()
            time.sleep(4)
            self.driver.back()
            #保存
            self.driver.find_element_by_id('com.ccvideo:id/living_action_tv').click()
            #拍照
            self.driver.find_element_by_id('com.ccvideo:id/btn_take_picture').click()
            self.driver.find_element_by_id('com.meizu.media.camera:id/shutter_btn').click()
            time.sleep(2)
            self.driver.find_element_by_id('com.meizu.media.camera:id/btn_done').click()
            #发送图片
            self.driver.find_element_by_id('com.ccvideo:id/btn_picture').click()
            self.driver.find_element_by_id('com.meizu.media.gallery:id/thumbnail_check_box').click()
            time.sleep(2)
            self.driver.find_element_by_id('com.meizu.media.gallery:id/action_get_multi_confirm').click()
            #发送位置
            self.driver.find_element_by_id('com.ccvideo:id/btn_location').click()
            time.sleep(2)
            self.driver.find_element_by_id('com.ccvideo:id/menu_send').click()
            time.sleep(2)
            #返回
            self.driver.back()
            #拉黑
            self.driver.find_element_by_id('com.ccvideo:id/pull_black_tv').click()
            self.driver.find_element_by_name("确定").click()
            time.sleep(3)
            #解除拉黑
            self.driver.find_element_by_id('com.ccvideo:id/pull_black_tv').click()
            time.sleep(3)
        finally:
            timestamp = time.strftime('%Y-%m-%d-%H-%M-%S',time.localtime(time.time()))
            os.popen("adb shell screencap -p /data/local/tmp/tmp.png")
            os.popen("adb pull /data/local/tmp/tmp.png E:\\Dev_Root\\python\\how_to_dev_python\\autobot\\android\\screenshot"  + "\\" + timestamp + ".png")
            time.sleep(5)
示例#20
0
from appium import webdriver
import time

from appium.webdriver.common.touch_action import TouchAction

desired_caps = {}
# 系统
desired_caps["platformName"] = "Android"
# 平台版本
desired_caps["platformVersion"] = "8.0"
# 设备号
desired_caps["deviceName"] = "WTKDU16716002118"
# 包名
desired_caps["appPackage"] = "com.android.settings"
# 启动名/界面名
desired_caps["appActivity"] = ".HWSettings"

# 连接appium服务器
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)

# 点击"无线和网络"
WLAN_button = driver.find_element_by_xpath("//*[@text='无线和网络']")
TouchAction(driver).tap(WLAN_button).perform()

# 利用坐标点击
TouchAction(driver).tap(x=400, y=800, count=1).perform()  # count--表示点击的次数
time.sleep(30)
driver.quit()
示例#21
0
 def long_press(self, ele, t=1000):
     """长按"""
     touch = TouchAction(driver)
     touch.long_press(ele).wait(t).release().perform()
示例#22
0
 def move_top(self):
     sleep(3)
     action = TouchAction(self._driver)
     rect = self._driver.get_window_rect()
     width, height = rect["width"], rect["height"]
     action.press(x=width * 0.5, y=height * 0.8).wait(200).move_to(x=width * 0.5, y=height * 0.2).release().perform()
示例#23
0
    def test_smiley_face(self):
        # just for the fun of it.
        # this doesn't really assert anything.
        self.driver.find_element_by_accessibility_id('Graphics').click()

        els = self.driver.find_elements_by_class_name('android.widget.TextView')
        self.driver.scroll(els[len(els)-1], els[0])

        el = None
        try:
            el = self.driver.find_element_by_accessibility_id('Touch Paint')
        except Exception as e:
            els = self.driver.find_elements_by_class_name('android.widget.TextView')
            self.driver.scroll(els[len(els)-1], els[0])

        if el is None:
            el = self.driver.find_element_by_accessibility_id('Touch Paint')

        el.click()

        # paint
        e1 = TouchAction()
        e1.press(x=150, y=100).release()

        e2 = TouchAction()
        e2.press(x=250, y=100).release()

        smile = TouchAction()
        smile.press(x=110, y=200) \
            .move_to(x=1, y=1) \
            .move_to(x=1, y=1) \
            .move_to(x=1, y=1) \
            .move_to(x=1, y=1) \
            .move_to(x=1, y=1) \
            .move_to(x=2, y=1) \
            .move_to(x=2, y=1) \
            .move_to(x=2, y=1) \
            .move_to(x=2, y=1) \
            .move_to(x=2, y=1) \
            .move_to(x=3, y=1) \
            .move_to(x=3, y=1) \
            .move_to(x=3, y=1) \
            .move_to(x=3, y=1) \
            .move_to(x=3, y=1) \
            .move_to(x=4, y=1) \
            .move_to(x=4, y=1) \
            .move_to(x=4, y=1) \
            .move_to(x=4, y=1) \
            .move_to(x=4, y=1) \
            .move_to(x=5, y=1) \
            .move_to(x=5, y=1) \
            .move_to(x=5, y=1) \
            .move_to(x=5, y=1) \
            .move_to(x=5, y=1) \
            .move_to(x=5, y=0) \
            .move_to(x=5, y=0) \
            .move_to(x=5, y=0) \
            .move_to(x=5, y=0) \
            .move_to(x=5, y=0) \
            .move_to(x=5, y=0) \
            .move_to(x=5, y=0) \
            .move_to(x=5, y=0) \
            .move_to(x=5, y=-1) \
            .move_to(x=5, y=-1) \
            .move_to(x=5, y=-1) \
            .move_to(x=5, y=-1) \
            .move_to(x=5, y=-1) \
            .move_to(x=4, y=-1) \
            .move_to(x=4, y=-1) \
            .move_to(x=4, y=-1) \
            .move_to(x=4, y=-1) \
            .move_to(x=4, y=-1) \
            .move_to(x=3, y=-1) \
            .move_to(x=3, y=-1) \
            .move_to(x=3, y=-1) \
            .move_to(x=3, y=-1) \
            .move_to(x=3, y=-1) \
            .move_to(x=2, y=-1) \
            .move_to(x=2, y=-1) \
            .move_to(x=2, y=-1) \
            .move_to(x=2, y=-1) \
            .move_to(x=2, y=-1) \
            .move_to(x=1, y=-1) \
            .move_to(x=1, y=-1) \
            .move_to(x=1, y=-1) \
            .move_to(x=1, y=-1) \
            .move_to(x=1, y=-1)
        smile.release()

        ma = MultiAction(self.driver)
        ma.add(e1, e2, smile)
        ma.perform()

        # so you can see it
        sleep(10)
    "udid": "192.168.56.101:5555",
    "noReset": True,
    "unicodeKeyboard": True,
    "resetKeyboard": True,
    "newCommandTimeout": 30
}
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", des)
# element01 = driver.find_element_by_xpath('//android.widget.TextView[@text="电池"]')
# TouchAction(driver).press(element01).release().perform()  # 点击操作
# long_press bug :放入元素操作的时候,会把元素的bounds属性 相加/2 得出x,y坐标 ,计算出现小数会导致坐标判断失败
# (因为坐标必须是整型)
# TouchAction(driver).long_press(None,216,1511,5000).perform()  # 长按操作 bug

element1 = driver.find_element_by_xpath(
    '//android.widget.TextView[@text="设置屏幕锁定"]')
touch_action = TouchAction(driver)
touch_action.press(element1).release().perform()
time.sleep(2)
element2 = driver.find_element_by_xpath(
    '//android.widget.TextView[@text="图案"]')
touch_action.press(element2).release().perform()
time.sleep(2)
# 287,1329  287,1762  725,1762  725,2196  1154,1762   725,1329
touch_action.press(x=287,y=1329).wait(1000)\
                    .move_to(x=287,y=1762).wait(1000)\
                    .move_to(x=725,y=1762).wait(1000)\
                    .move_to(x=725,y=2196).wait(1000)\
                    .move_to(x=1154,y=1762).wait(1000)\
                    .move_to(x=725,y=1329).wait(1000)\
                    .release().perform()
示例#25
0
 def app_press(self, x, y):
     action = TouchAction(self.driver)
     return action.press(x, y).perform()
示例#26
0
from appium import webdriver
from appium.webdriver.common.touch_action import TouchAction
from InitAppiumDriver import desired_Cap
import unittest
import time

desired_cap = desired_Cap()

# Create Test Driver
driver = webdriver.Remote("http://localhost:4723/wd/hub", desired_cap)
driver.implicitly_wait(30)
user_action = TouchAction(driver)

##ID: 02200’x.y = 32(shopBydept_Electronics)
##Class: android.widget.ImageView

el1 = driver.find_element_by_accessibility_id("Open navigation drawer")
el1.click()
time.sleep(8)
user_action.tap(x=304, y=879).perform()

time.sleep(8)
user_action.tap(x=131, y=620).perform()
示例#27
0
 def app_move_to(self, x, y):
     action = TouchAction(self.driver)
     return action.move_to(x, y).perform()
示例#28
0
def scroll_up(driver):
    action = TouchAction(driver)
    action.press(x=500, y=500).move_to(x=500, y=130).release().perform()
示例#29
0
# 连接appium服务器
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
"""
九宫格手势密码绘制案例 柠檬班119节开始
"""
# 找到包裹九宫格的那个元素(以下简称元素),是个正方形
ele = driver.find_element_by_id("")
# 获取包裹九宫格的元素的大小
size = ele.size
# 均分的步长 高和宽一样
step = size["width"] / 6  # 九个点将正方形平均分成了6份
# 元素的起点坐标 ——左上角
ori = ele.location
point1 = (ori["x"] + step, ori["y"] + step)  # 九宫格中第一个点
point2 = (point1[0] + step * 2, point1[1])  # 九宫格中第二个点:相对于point1,X轴增加了2*step
point3 = (point2[0] + step * 2, point2[1])  # 九宫格中第三个点:相对于point2,X轴增加了2*step
point4 = (point3[0] - step * 2, point3[1] + step * 2
          )  # 九宫格中第五个点:相对于point3,X轴减少了2*step,Y轴增加了2*step
point5 = (point4[0], point4[1] + step * 2
          )  # 九宫格中第八个点:相对于point4,X轴不变,Y轴增加了2*step

TouchAction(driver).press(x=point1[0], y=point1[1]).wait(200).\
    move_to(x=point2[0], y=point2[1]).\
    move_to(x=point3[0], y=point3[1]).\
    move_to(x=point4[0], y=point4[1]).\
    move_to(x=point4[0], y=point4[1]).\
    release().\
    perform()

# 120节Appium常用操作(二)看完
示例#30
-1
 def zh_login(self, wechat_list):
     self.driver.implicitly_wait(5)
     if self.driver.find_elements_by_name(self.element_json['allow']) != []:
         self.driver.find_element_by_name(self.element_json['allow']).click()
         self.driver.find_element_by_name(self.element_json['allow']).click()
     self.driver.implicitly_wait(30)
     self.driver.find_element_by_name(self.element_json['login']).click()
     self.driver.find_element_by_id(self.element_json[u'输入框ID']).click()
     os.system('adb -s %s shell input text %s' % (self.deviceid, wechat_list[0]))
     self.visualization('输入账号')
     logging.info(self.deviceid + u'-输入账号')
     self.driver.find_element_by_id(self.element_json[u'输入手机号码登陆下一步']).click()
     self.visualization('下一步')
     logging.info(self.deviceid + u'-下一步')
     self.driver.find_elements_by_id(self.element_json[u'输入框ID'])[1].click()
     os.system('adb -s %s shell input text %s' % (self.deviceid, wechat_list[1]))
     self.visualization('输入密码')
     logging.info(self.deviceid + u'-输入密码')
     self.driver.find_element_by_id(self.element_json[u'输入手机号码登陆下一步']).click()
     self.visualization('登录')
     logging.info(self.deviceid + u'-登录')
     self.driver.implicitly_wait(2)
     while True:
         if self.driver.find_elements_by_id(self.element_json[u'错误弹窗内容ID']) != []:
             self.cw = self.driver.find_element_by_id(self.element_json[u'错误弹窗内容ID']).get_attribute(('text'))
             return self.error_message()
         if self.driver.find_elements_by_id(self.element_json[u'微信四个主按钮ID']) != []:
             break
         if self.driver.find_elements_by_android_uiautomator('new UiSelector().description("拖动下方滑块完成拼图")') != []:
             logging.info(u'%s-进入滑图页面' % self.deviceid)
             while True:
                 for j in range(100, 200, 30):
                     try:
                         a = TouchAction(self.driver)
                         a.press(x=250, y=1000)
                         for i in range(0, 5):
                             a.move_to(x=50, y=(random.randint(-500, 0))).wait(0)
                             a.move_to(x=50, y=(random.randint(0, 500))).wait(0)
                         for i in range(0, j / 10):
                             a.move_to(x=10, y=0).wait(100)
                         a.release().perform()
                     except:
                         pass
                 if self.driver.find_elements_by_android_uiautomator('new UiSelector().description("开始验证 ")') != []:
                     file().write('%s\n' % wechat_list[0], '新设备记录文本.txt')
                     logging.info(u'%s-%s该账号出现新设备' % (self.deviceid, wechat_list[0]))
                     self.driver.quit()
                     break
                 if self.driver.find_elements_by_id(self.element_json[u'输入手机号码登陆下一步']) != []:
                     self.driver.find_element_by_id(self.element_json[u'输入手机号码登陆下一步']).click()
                     break
                 if self.driver.find_elements_by_android_uiautomator('new UiSelector().description("声音锁验证 ")') != []:
                     file().write('%s\n' % wechat_list[0], '新设备记录文本.txt')
                     logging.info(u'%s-%s该账号出现新设备' % (self.deviceid, wechat_list[0]))
                     self.driver.quit()
                     break
         if self.driver.find_elements_by_android_uiautomator('new UiSelector().description("开始验证 ")') != []:
             file().write('%s\n' % wechat_list[0], '新设备记录文本.txt')
             logging.info(u'%s-%s该账号出现新设备' % (self.deviceid, wechat_list[0]))
             self.driver.quit()
             break