iOS自动化测试方案及其环境搭建 - Cucumber

2112 篇文章 51 订阅
840 篇文章 1 订阅

软件测试面试刷题,这个小程序(永久刷题),靠它可以快速找到工作!https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502icon-default.png?t=N7T8https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502

什么是Cucumber?

  • Cucumber 是一个能够理解用普通语言描述的测试用例的行为驱动开发(BDD)的自动化测试工具,用Ruby**编写,支持Java和·Net等多种开发语言。

  • Cucumber可以让人们用近似自然的语言去描述Feature和场景,根据Feature驱动开发。用作软件技术人员和非技术之间验收测试的桥梁。它是一个命令行工具。运行后,会执行features中的内容。feature中的step会调用stepdefinitions(Ruby代码)可以用标签来组织场景支持40多种语言高质量集成Ruby。

简单说,Cucumber可以让你通过自然语言编写测试场景,并且支持用你喜欢的脚本语言去编写测试脚本。

接下来我们开始对Cucumber进行搭建。安装步骤如下:

1、安装ruby环境

gem source -a https://gems.ruby-china.com

一般来说,你如果有用过cocoapods,那么就会有安装ruby。先查询ruby版本ruby -v,我的是ruby 2.6.3版本

2、去Cucumber官网查看相关安装命令。这里贴出一句:

gem install cucumber

Cucumber安装好之后,我们就可以利用Cucumber建立工程了,下面跟着我的步骤进行来一起进行创建吧。我这里是搭建的是Ruby环境,你可以根据自己的需求和习惯去搭建对应的语言环境。

1、新建文件夹存放项目(JNCucumberDemo)

cd Desktopmkdir JNCucumberDemo

2、初始化cucumber

cucumber --init

执行上面命令,会生成如下目录结构:

features # 存放feature的目录
├── step_definitions # 存放steps的目录
└── support # 环境配置
   └── env.rb

3、创建Gemfile文件

touch Gemfile

打开Gemfile,导入Ruby库

source 'https://www.rubygems.org'
gem 'appium_lib'

gem 'rest-client'

gem 'rspec'gem 'cucumber'gem 'rspec-expectations'gem 'spec'gem 'sauce_whisk'gem 'test-unit'

如果命令行报bundler加载没有权限的警告,可以执行

sudo gem install bundler

4、安装ruby依赖库

# 需要先安装bundle,如果已安装bundle请直接执行bundle installgem install bundle# 安装ruby依赖bundle install

5、新建apps目录
apps目录用于存放,被测试的app包

mkdir apps

运行目标项目,在Products文件夹中找到.app结尾的包,放到apps目录下,等待测试。

图片

6、配置运行基本信息
进入features/support目录,新建appium.txt文件。
编辑appium.txt文件,这里只配置了iOS的模拟器和真正代码。这里是真机。

 [caps]

# 模拟器

#platformName = "iOS"

#deviceName = "iPhone 11 Pro"

#platformVersion = "13.2"

#app = "./apps/JNAuto.app"

#automationName = "XCUITest"

##noReset="true"



# 真机

platformName = "iOS"

deviceName = "iPhone 6"

platformVersion = "12.4"

app = "./apps/JNAuto.app"

automationName = "XCUITest"

udid = ""xcodeOrgId = ""

xcodeSigningId = "iPhone Developer"

autoAcceptAlerts = "true"  

waitForAppScript = "$.delay(5000); $.acceptAlert();" # 处理系统弹窗





[appium_lib]

sauce_username = false

sauce_access_key = false

其中的xcodeOrgId去开发者账号下找对应的TeamID填上即可

注:如果使用模拟器可以使用语句查看系统支持的模拟器版本

xcrun simctl list devices

打开env.rb文件,配置启动入口。

# This file provides setup and common functionality across all features.  It's

# included first before every test run, and the methods provided here can be

# used in any of the step definitions used in a test.  This is a great place to

# put shared data like the location of your app, the capabilities you want to

# test with, and the setup of selenium.



require 'rspec/expectations'

require 'appium_lib'

#require 'cucumber/ast'

# Create a custom World class so we don't pollute `Object` with Appium methods





class AppiumWorld

end



caps = Appium.load_appium_txt file: File.expand_path('../appium.txt', __FILE__), verbose:           true

# end





Appium::Driver.new(caps, true)

Appium.promote_appium_methods AppiumWorld





World do

   AppiumWorld.new

end





Before { $driver.start_driver }

After { $driver.driver_quit }

Tips:

执行Cucumber之前记得启动Appium Server客户端。

到这里Cucumber的环境便搭建好了,UI自动化测试还有很多待探究和深挖的地方。今后会不断对该文章进行更新和完善,敬请期待吧!!!

Tips:
贴出Cucumber自然语言语法

图片

行动吧,在路上总比一直观望的要好,未来的你肯定会感谢现在拼搏的自己!如果想学习提升找不到资料,没人答疑解惑时,请及时加入群: 759968159,里面有各种测试开发资料和技术可以一起交流哦。

最后: 下方这份完整的软件测试视频教程已经整理上传完成,需要的朋友们可以自行领取【保证100%免费】

​​​软件测试面试文档

我们学习必然是为了找到高薪的工作,下面这些面试题是来自阿里、腾讯、字节等一线互联网大厂最新的面试资料,并且有字节大佬给出了权威的解答,刷完这一套面试资料相信大家都能找到满意的工作。

在这里插入图片描述

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值