我有一个完整的自动化测试套件,它使用 ruby 和 Appium 编写,用于移动自动化。
我在一台机器上的一个模拟器中运行这些套件,运行 56 个测试用例大约需要 1 小时(我们有系统测试用例,其中集成了数据库/Api/功能等多项检查)。我们有更多额外的测试用例添加到我们的方式中。
我们已经实现了在 3 台 mac 机器上运行我们的测试,目前运行不同的 cucumber 标签集成到 Jenkins。然而,更多的测试只会花费我们更多的时间或更多的mac
使用 xcode 9,我们可以同时在一台机器上启动多个模拟器,我想知道,是否有任何示例场景或文档说明如何在一台 mac 机器上跨模拟器实现分布式测试
我曾尝试使用不同的平台版本加载两个或三个不同的所需功能,但它只按顺序加载测试。
我在网上浏览了很多 Material ,这些 Material 只有在 android 中实现这一点的步骤。 iOS 支持吗?
或者任何人都可以提供对我有帮助的链接吗?到
1.在一台mac中实现跨各种模拟器的分布式测试
2. 使用 cucumber 标签分发测试,为每个所需的功能创建实例
更新:
我曾尝试实现多线程选项,并尝试对每个线程创建实例的特定模拟器启动测试。但是,我发现测试不是并行运行而是顺序运行。
这是我的代码:
def start_app(device_id, wdalocalport)
caps_config = {
platformName: "iOS",
wdaLocalPort: wdalocalport,
deviceName: "iPhone Simulator", #update device as per your need
app: (File.join(File.dirname(__FILE__), "Sequoia.app")),
bundleId: "something",
automationName: "XCUITest",
xcodeOrgId: "something",
xcodeSigningId: "iPhone Developer",
#platformVersion: "10.2",
noReset: "true",
fullReset: "false",
showIOSLog: "true",
autoAcceptAlerts: "true",
showXcodeLog: "true",
useNewWDA: "true",
resetOnSessionStartOnly: "true",
udid: device_id }
appium_lib_config={ port: 4723 }
$opts={ caps: caps_config, appium_lib: appium_lib_config }
setup
end
def setup
@appium = Appium::Driver.new($opts)
@appium.start_driver
#Makes all appium_lib methods accessible from steps
#Starts appium driver before the tests begin
end
def test(device1,device2)
threads = []
threads << Thread.new {
start_app(device1, '8100')
}
threads << Thread.new {
start_app(device2, '8200')
}
threads.each(&:join)
end
end
我正在使用
test
调用启动测试传递 udid's
的方法.模拟器同时启动,同时安装应用程序,但测试不是并行的。对即兴创作这个案子有什么帮助吗?
我能够使用
rake
并行运行,但我仍然发现这种方法以顺序方式运行测试或根本不运行PFB 代码
def run_cucumber(cucumber_options)
Cucumber::Rake::Task.new do |t|
t.cucumber_opts = cucumber_options
end
Rake::Task[:cucumber].invoke
end
task :iphone_7 do |t|
ENV['DEVICE'] = 'iphone7'
run_cucumber('-r features features/test.feature --format pretty --tags @slave1')
end
task :iphone_8 do |t|
ENV['DEVICE'] = 'iphone8'
run_cucumber('-r features features/test.feature --format pretty --tags @slave2')
end
multitask :all => [:iphone_7,:iphone_8]
我的
hooks.rb
Before do
check
end
def check
if ENV['DEVICE'] == 'iphone7'
start_app('iPhone6','port','udid')
elsif ENV['DEVICE'] == 'iphone8'
start_app('iphone6','port','udid')
else
puts "Device not"
end
end
我得到了
DEVICE NOT
.不知道我错过了什么。
最佳答案
您需要在 Rakefile 中创建一个首先调用 cucumber rake 的方法,如下所示:
def run_cucumber(cucumber_options)
Cucumber::Rake::Task.new do |t|
t.cucumber_opts = cucumber_options
end
Rake::Task[:cucumber].invoke
end
此方法将需要 cucumber_options。您可以传递与在命令行上传递相同的选项,如下所示:
-r features features/test.feature --format pretty --tags @test1
在此之后,在同一个 Rakefile 中为特定配置定义 rake 任务:
task :iphone_7 do |t|
ENV["DEVICE"] = "iphone 7"
run_cucumber('-r features features/test.feature --format pretty --tags @test1')
end
task :iphone_8 do |t|
ENV["DEVICE"] = "iphone 8"
run_cucumber('-r features features/test.feature --format pretty --tags @test2')
end
这里,ENV["DEVICE"] 用于设置设备配置。您可以在 Before block 中的 env.rb 中使用此变量来初始化测试。在 Before block 中,您可以根据此环境变量初始化设备。
您可以根据需要创建尽可能多的这样的 rake 任务。
然后,您可以使用 ruby 的并行 gem 同时调用多个任务。示例在此链接中-> Ruby Parallel gem
只需将不同类型的 rake 任务作为 Parallel 对象中的参数传递。
例如:
task :run_parallel do |t|
Parallel.map([:iphone_7,:iphone_8]) {|task| Rake::Task[task].invoke }
end
然后触发 run_parallel rake 任务执行整个代码。
例如:
bundle exec rake run_parallel
关于ios - Appium:Ruby:使用 appium for iOS 进行分布式测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46340501/