如何进行点击/水龙头操作势必/坐标在python脚本使用appium的Andr​​oid UI的perticular [英] How to perform click/tap operation to the perticular bound/co-ordinates in python script for Android UI using appium

查看:457
本文介绍了如何进行点击/水龙头操作势必/坐标在python脚本使用appium的Andr​​oid UI的perticular的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用appium写python脚本测试用例的Andr​​oid应用程序。我想在一个特定的范围/坐标进行点击/点击操作。但我不能够执行it.Can任何一个可以告诉我该怎么做。

I am writing testcases in python script for android application using appium. I want to perform click/tap operation in a particular bounds/co-ordinates. but I am not able to perform it.Can any one tell me how to do it.

类firstTest(unittest.TestCase的):

class firstTest(unittest.TestCase):

def tearDown(self):
    "Tear down the test"
    self.driver.quit()

def test_single_player_mode(self):
    time.sleep(5)
    element = self.driver.find_element_by_name("Enter your Email ID or User name")
    element.send_keys("username")
    element = self.driver.find_element_by_name("Let's get started!")
    element.click()
    time.sleep(5)

直到让我们开始这是工作的罚款。后在UI中,我没有任何元素名称或ID。我只是特别势必单击该元素。我想点击绑定[918154] [1086,324]对于上述约束资源ID为com.abc.android.cap:ID / friends_selection_list请告诉我如何后,做

Till 'Lets get started it is working fine. After it in UI, I don't have any element name or id. I have only particular bound to click the element. I want to click on bound [918,154][1086,324] resource ID for above bound is "com.abc.android.cap:id/friends_selection_list" Please tell me how to do after it.

推荐答案

U可以使用XPath的元素,用于查找的XPathü将需要appium检查,它仅支持MAC OSX,所以你必须使用Mac和为了得到它的工作配置Android SDK和Appium上的MAC。 code将是这样的:

U can use Xpath of that element, for finding xpath u will need appium inspector, which is supported in MAC OSX only, so you have to use an mac and configure Android SDK and Appium on MAC in order to get it working. Code will be like this :

 #-*- coding: utf-8 -*-
__author__ = 'chetan.krishna'
import os
import time
import unittest
from time import sleep
from appium import webdriver
from pylab import *
from teamcity import is_running_under_teamcity
from teamcity.unittestpy import TeamcityTestRunner
import logging

# Returns absolute path relative to this file
PATH = lambda p: os.path.abspath(
    os.path.join(os.path.dirname(__file__), p)
)


class AvavntiAndroidTests(unittest.TestCase):
    def setUp(self):
        desired_caps = {}
# Specify platform below(Android, iOS)
        desired_caps['platformName'] = 'Android'
# Specify OS version(Settings->About phone -> android version)
        desired_caps['platformVersion'] = '4.4.4'
# Obtain the Device name from Adb[For Android](Terminal Command: "adb devices")
        desired_caps['deviceName'] = '4d0081004c8741a9'

        desired_caps['noReset'] = False
# Specify the path to Application
        desired_caps["app"] = PATH('AvantiMarket_v1.4.apk')
# Wait for email login activity to appear
        desired_caps["appWaitActivity"]= ('com.android.avantimarket.ui.activity.EmailLoginActivity')
        self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

    def tearDown(self):
# end the session
        self.driver.quit()


    def test_Avanti(self):
# wait for the login screen to appear
        self.driver.implicitly_wait(20)
# set values for plotting pass and fail results
        nPass = 0
        nFail = 0
        print('Checking login for registered user')
    # Logging in as indiaone@avantilab.org
elf.driver.implicitly_wait('20')
        print('Trying to login with abc@abc.org')
        self.driver.find_element_by_xpath('//UIAApplication[1]/UIAWindow[2]/UIATextField[1]').send_keys('abc@abc.org.org')
        self.driver.find_element_by_xpath('//UIAApplication[1]/UIAWindow[2]/UIASecureTextField[1]').send_keys('12345678')
        self.driver.hide_keyboard()
        self.driver.implicitly_wait(10)
        self.driver.find_element_by_xpath('//UIAApplication[1]/UIAWindow[2]/UIAButton[3]').click()
        time.sleep(20)
        self.driver.implicitly_wait(99)
        try:
            self.driver.find_element_by_xpath('//UIAApplication[1]/UIAWindow[2]/UIASecureTextField[1]')
        except :
            print('Login failed, please check credentials and network')
        else:
            print('Login successful, creating pin')

        self.driver.find_element_by_xpath('//UIAApplication[1]/UIAWindow[2]/UIASecureTextField[1]').send_keys('1')
        self.driver.find_element_by_xpath('//UIAApplication[1]/UIAWindow[2]/UIASecureTextField[2]').send_keys('1')
        self.driver.find_element_by_xpath('//UIAApplication[1]/UIAWindow[2]/UIASecureTextField[3]').send_keys('1')
        self.driver.find_element_by_xpath('//UIAApplication[1]/UIAWindow[2]/UIASecureTextField[4]').send_keys('1')
        self.driver.find_element_by_xpath('//UIAApplication[1]/UIAWindow[2]/UIASecureTextField[5]').send_keys('1')
        self.driver.find_element_by_id('com.android.avantimarket:id/m_emailTextField').send_keys('abc@abc.org.org')
        self.driver.back()
        nPass= nPass+1
        self.driver.implicitly_wait(20)
        self.driver.find_element_by_id('com.android.avantimarket:id/m_passwordTextField').send_keys('12345678')
        nPass= nPass+1
        self.driver.back()
        self.driver.implicitly_wait(10)
        self.driver.find_element_by_name('SIGN IN').click()
        self.driver.implicitly_wait(30)
        time.sleep(5)
# validating for successful login
        try:
            self.driver.find_element_by_id('com.android.avantimarket:id/create_pin_fields_container')
            print('Login successful')
            nPass= nPass+1
        except:
            print('Login failed')
            nFail = nFail + 1
        else:
# Creating pin required for login
            print('Creating Pin for user')
        self.driver.find_element_by_id('com.android.avantimarket:id/create_pin_fields_container').send_keys('1111')
        self.driver.find_element_by_id('com.android.avantimarket:id/reEnter_pin_fields_container').send_keys('1111')
        self.driver.back()
        self.driver.implicitly_wait(20)
        self.driver.find_element_by_id('com.android.avantimarket:id/m_saveButton').click()
        self.driver.implicitly_wait(10)
        self.driver.find_element_by_id('com.android.avantimarket:id/btn_cominsoon_Yes').click()
        self.driver.implicitly_wait(10)
        time.sleep(8)

这篇关于如何进行点击/水龙头操作势必/坐标在python脚本使用appium的Andr​​oid UI的perticular的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆