当前位置:网站首页>[appium] write scripts by designing Keyword Driven files
[appium] write scripts by designing Keyword Driven files
2022-04-23 17:42:00 【BetterFate!】
Preface : Drive files through keywords , Separate the script from the test case , It allows people with weak code to fill in the parameters required for use cases in a format , You can run automated scripts , It also makes the code more concise .
Catalog
Two 、 Script according to the file
One 、 Design driver file
This passage csv file To write test cases , In addition to the basic elements of use cases ID、name、 describe outside , In order to associate with the script, add How elements are positioned 、 The element object itself 、 Operation method 、 Test data , Of course, the actual situation is still based on the project requirements .
csv The preliminary design of the document is as follows :
Be careful : The test steps have to be written in the order of the actual test , Don't mess up
Two 、 Script according to the file
First, clarify the positioning method , I used to use driver.find_element(By.ID, ' Elements id') such By. The way Methods , But there is another way :driver.find_element('id', ' Elements id') This method is also possible .
Other corresponding properties are as follows :
- ID = "id"
- XPATH = "xpath"
- LINK_TEXT = "link text"
- PARTIAL_LINK_TEXT = "partial link text"
- NAME = "name"
- TAG_NAME = "tag name"
- CLASS_NAME = "class name"
- CSS_SELECTOR = "css selector"
Be careful : There should be no fewer spaces , stay csv The positioning method filled in the must also be based on this
The script for reading the file is as follows :
def test_addnote(self):
# Read the keyword driven test case file
file = open('keyframe.csv', 'r')
table = csv.reader(file)
header = next(table) # Skip the first line
for row in table:
# print(row[3])
if row[6] == 'click':
self.driver.find_element(str(row[4]), str(row[5])).click()
elif row[6] == 'send_keys':
self.driver.find_element(str(row[4]), str(row[5])).send_keys(str(row[7]))
The example is that there is a cloud on the simulator used app Add notes , The complete code is as follows :
# Import Appium Class library
from appium.webdriver.webdriver import WebDriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
import csv
class yd_addnote():
# Use the initialization method to set the test parameters
def __init__(self):
self.caps = {
'automationName': 'UiAutomator2',
'platformName': 'Android',
'platformVersion': '6.0',
'deviceName': '192.168.23.101:5555',
'appPackage': 'com.youdao.note',
'appActivity': '.activity2.MainActivity'}
self.driver = WebDriver('http://127.0.0.1:4723/wd/hub', self.caps)
self.driver.implicitly_wait(10)
# Enter Youdao cloud
el = WebDriverWait(self.driver, 10).until(
lambda x: x.find_element(By.ID, 'com.android.packageinstaller:id/permission_allow_button'))
if el:
# Click the Agree button
self.driver.find_element(By.ID, 'com.android.packageinstaller:id/permission_allow_button').click()
def test_addnote(self):
# Read the keyword driven test case file
file = open('keyframe.csv', 'r')
table = csv.reader(file)
header = next(table) # Skip the first line
for row in table:
# print(row[3])
if row[6] == 'click':
self.driver.find_element(str(row[4]), str(row[5])).click()
elif row[6] == 'send_keys':
self.driver.find_element(str(row[4]), str(row[5])).send_keys(str(row[7]))
if __name__ == '__main__':
addnote = yd_addnote()
addnote.test_addnote()
版权声明
本文为[BetterFate!]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231739290846.html
边栏推荐
- Router object, route object, declarative navigation, programmed navigation
- 239. Maximum value of sliding window (difficult) - one-way queue, large top heap - byte skipping high frequency problem
- Solution of Navicat connecting Oracle library is not loaded
- 958. Complete binary tree test
- 一些问题一些问题一些问题一些问题
- HCIP第五次实验
- Generating access keys using JSON webtoken
- Using quartz under. Net core - [1] quick start
- Seven cattle upload pictures (foreground JS + background C API get token)
- Leak detection and vacancy filling (6)
猜你喜欢
Halo open source project learning (II): entity classes and data tables
440. The k-th small number of dictionary order (difficult) - dictionary tree - number node - byte skipping high-frequency question
JS parsing and execution process
Matlab / Simulink simulation of double closed loop DC speed regulation system
958. 二叉树的完全性检验
Dry goods | how to extract thumbnails quickly?
470. Rand10() is implemented with rand7()
XTask与Kotlin Coroutine的使用对比
How to change input into text
索引:手把手教你索引从零基础到精通使用
随机推荐
48. Rotate image
剑指 Offer 22. 链表中倒数第k个节点-快慢指针
Using quartz under. Net core -- a simple trigger of [7] operation and trigger
Entity Framework core captures database changes
Model problems of stock in and stock out and inventory system
Qt 修改UI没有生效
209. Minimum length subarray - sliding window
XTask与Kotlin Coroutine的使用对比
为什么有些人说单片机简单,我学起来这么吃力?
Construction of functions in C language programming
超分之TDAN
[related to zhengheyuan cutting tools]
1217_ Generating target files using scons
239. 滑动窗口最大值(困难)-单向队列、大顶堆-字节跳动高频题
JS interview question: FN call. call. call. Call (FN2) parsing
Using quartz under. Net core -- preliminary understanding of [2] operations and triggers
Index: teach you index from zero basis to proficient use
Using quartz under. Net core -- general properties and priority of triggers for [5] jobs and triggers
Tdan over half
flink 学习(十二)Allowed Lateness和 Side Output