Appium AppiumBooster 新增支持 YAML 格式的测试用例

debugtalk · 2016年08月18日 · 最后由 bruceBingo 回复于 2018年07月11日 · 1924 次阅读

AppiumBooster

AppiumBooster helps you to write automation testcases in yaml format or csv tables, without writing a snippet of code.

write testcases in yaml (recommended)

Take DJI+ Discover's login and logout function as an example.

preview of login and logout

In order to test these functions above, you can write testcases in yaml format like this.

# ios/testcases/Account.yml
---
AccountTestcases:
  login with valid account:
    - AccountSteps | enter My Account page
    - AccountSteps | enter Login page
    - AccountSteps | input EmailAddress
    - AccountSteps | input Password
    - AccountSteps | login
    - AccountSteps | close coupon popup window(optional)

  logout:
    - AccountSteps | enter My Account page
    - SettingsSteps | enter Settings page
    - AccountSteps | logout

In the testcases, each step is combined with two parts, joined by a separator |. The former part indicates step file located in ios/steps/ directory, and the latter part indicates testcase step name, which is defined in steps yaml files like below.

# ios/steps/AccountSteps.yml
---
AccountSteps:
  enter My Account page:
    control_id: btnMenuMyAccount
    control_action: click
    expectation: tablecellMyAccountSystemSettings

  enter Login page:
    control_id: tablecellMyAccountLogin
    control_action: click
    expectation: btnForgetPassword

  input EmailAddress:
    control_id: txtfieldEmailAddress
    control_action: type
    data: leo.lee@debugtalk.com
    expectation: sectxtfieldPassword

  input Password:
    control_id: sectxtfieldPassword
    control_action: type
    data: 123456
    expectation: btnLogin

  login:
    control_id: btnLogin
    control_action: click
    expectation: tablecellMyMessage

write testcases in tables

You can also write testcases in any table tools, including MS Excel and iWork Numbers, and even in plain CSV format.

In order to test the same functions above, you can write testcases in tables like this.

testcases of login and logout

After the testcases are finished, export to CSV format, and put the csv files under ios/testcases/ directory.

run

Once the testcases are done, you are ready to run automation test on your app.

Run the automation testcases is very easy. You can execute ruby run.rb -h in the project root directory to see the usage.

➜  AppiumBooster git:(master) ✗ ruby run.rb -h
Usage: run.rb [options]
    -p, --app_path APP_PATH              Specify app path
    -t, --app_type APP_TYPE              Specify app type, ios or android
    -f, --testcase_file TESTCASE_FILE    Specify testcase file
        --disable_output_color           Disable output color

AppiumBooster will load all the csv test suites and then excute each suite sequentially.

➜  AppiumBooster git:(master) ✗ ruby run.rb -p "ios/app/test.zip" -f "ios/testcases/Account.yml"
initialize appium driver ...
load testcase yaml file: /Users/Leo/MyProjects/AppiumBooster/ios/testcases/Account.yml
load steps yaml file: /Users/Leo/MyProjects/AppiumBooster/ios/steps/AccountSteps.yml
load steps yaml file: /Users/Leo/MyProjects/AppiumBooster/ios/steps/SettingsSteps.yml
start appium driver ...

======= start to run testcase suite: /Users/Leo/MyProjects/AppiumBooster/ios/testcases/Account.yml =======
B------ Start to run testcase: login with valid account
step_1: enter My Account page
btnMenuMyAccount.click     ...    ✓
step_2: enter Login page
tablecellMyAccountLogin.click     ...    ✓
step_3: input EmailAddress
txtfieldEmailAddress.type leo.lee@debugtalk.com    ...    ✓
step_4: input Password
sectxtfieldPassword.type 123456    ...    ✓
step_5: login
btnLogin.click     ...    ✓
step_6: close coupon popup window(optional)
btnClose.click     ...    ✓
E------ login with valid account

B------ Start to run testcase: logout
step_1: enter My Account page
btnMenuMyAccount.click     ...    ✓
step_2: enter Settings page
tablecellMyAccountSystemSettings.click     ...    ✓
step_3: logout
btnLogout.click     ...    ✓
E------ logout

============ all testcases have been executed. ============
quit appium driver.

Source Code

GitHub: https://github.com/debugtalk/AppiumBooster

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 7 条回复 时间 点赞

yaml 看起来挺小清新

可是没法做逻辑判断呀

#1 楼 @seveniruby 是啊,相比于表格的优势是,可以把每一步操作定义为基础元素,然后在写测试用例的时候可以实现复用

#2 楼 @codeskyblue 每一步操作都会有个 expectation 来检查当前步骤是否成功;上层的逻辑判断是在测试用例中实现的

#4 楼 @debugtalk 是不是用 python 代码或者 js 代码来控制是否执行那个 yaml 文件

#5 楼 @codeskyblue 不是。yaml 用于描述测试用例;是否执行某个测试用例是在执行命令中指定。

指定执行的测试用例

支持两种方式:

  • -f specified_testcase,指定特定测试用例文件
  • -f multiple_testcases,通过通配符匹配多个测试用例文件

e.g.

$ cd ${AppiumBooster}
# 执行指定的测试用例文件
$ ruby run.rb -p "ios/app/test.zip" -f "ios/testcases/Settings.yml"

# 执行所有yml格式的测试用例文件
$ ruby run.rb -p "ios/app/test.zip" -f "*.yml"

# 执行所有csv格式的测试用例文件
$ ruby run.rb -p "ios/app/test.zip" -f "*.csv"

如何实现真机的测试,试了很多方式,这种类型测试用例貌似没法执行啊

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册