Skip to content

Commit 4b640b5

Browse files
author
Javon Davis
committed
Merge branch 'release/0.2.4'
2 parents 6de4ac9 + cc94c5a commit 4b640b5

File tree

9 files changed

+213
-22
lines changed

9 files changed

+213
-22
lines changed

.gitignore

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,4 +454,12 @@ hsd-report
454454

455455
tmp/
456456

457-
.vscode/
457+
.vscode/
458+
459+
*.sh
460+
461+
apps
462+
463+
*.apk
464+
*.app
465+
*.zip

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
parallel_appium (0.1.1)
4+
parallel_appium (0.2.3)
55

66
GEM
77
remote: https://rubygems.org/

README.md

Lines changed: 156 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,178 @@
11
# parallel_appium
22

3-
Distributed mobile testing in Appium
3+
Single/Distributed Parallel Cross-Platform mobile testing in Appium and RSpec for Android and iOS.
4+
5+
This project acts as a wrapper around a number of the configurations that have to be in place for
6+
running appium tests with RSpec.
7+
8+
The Gem:
9+
10+
* Handles single platform testing
11+
* Does cross-platform testing in Parallel
12+
* Distributes tests across multiple simulator instances for a platform
13+
14+
Using the gem will speed up the time your entire test suite takes to execute and reducing your
15+
project size by packaging a lot of code that is not context-specific.
16+
17+
This project depends on [Appium](http://appium.io/), please ensure you've installed and configured Appium
18+
correctly before trying to work with this gem. [Appium Doctor](https://github.com/appium/appium-doctor) is a good way to
19+
ensure you're good to go here
20+
21+
## Sample Project
22+
23+
To better demonstrate how to use the gem, a project automating Wordpress's mobile apps
24+
is presented [here](https://github.com/JavonDavis/Wordpress-Open-Source-Automation-Ruby).
25+
26+
This project shows hands on how to integrate the gem and what it can do.
427

528
## Installation
629

730
Add this line to your application's Gemfile:
831

9-
```ruby
32+
```
1033
gem 'parallel_appium'
1134
```
1235

1336
And then execute:
1437

15-
$ bundle
38+
$ bundle install
1639

1740
Or install it yourself as:
1841

1942
$ gem install parallel_appium
43+
44+
## Getting setup
45+
46+
## Android
47+
48+
The gem uses the emulator command line tool that comes with your Android installation to manage a number of things. This
49+
however requires a bit of configuration to work properly as by default it's not added to the system path and it's usually
50+
not pointing to the correct one. Adding something like this(**in the specified order**) in your bash_profile will resolve
51+
this
52+
53+
```
54+
export ANDROID_HOME=/<path>/to/Android/sdk
55+
export ANDROID_AVD_HOME=~/.android/avd
56+
export PATH=$ANDROID_HOME/platform-tools:$PATH
57+
export PATH=$ANDROID_HOME/tools:$PATH
58+
export PATH=$ANDROID_HOME/tools/bin:$PATH
59+
export PATH=$ANDROID_HOME/emulator:$PATH
60+
```
61+
62+
## iOS
63+
64+
The main requirement here is to be running on a MAC machine, otherwise, there's nothing extra to do here
65+
all the requirements for Appium and iOS hold true.
66+
67+
### Additional check
68+
69+
I also recommend an additional check to see if you're good to go for this project, simply execute
70+
71+
```bundle install --path vendor```
72+
73+
and then
74+
75+
```bundle exec rake parallel_appium:validate_android``` for Android
76+
77+
or
78+
79+
```bundle exec rake parallel_appium:validate_ios``` for iOS
80+
81+
82+
The messages will indicate if there's any component necessary for the platform that's still not set up as yet.
83+
2084

2185
## Usage
2286

23-
TODO: Write usage instructions here
87+
To get started with this gem in a project there's 3 lines of code you'll need to know to include within your project.
88+
These lines handle the following.
89+
90+
### Starting the servers
91+
92+
The library at the moment doesn't offer the ability to connect to existing appium processes and instead
93+
starts appium servers and the selenium grid server as needed. The following line of code is what you'll need to include
94+
for the library to handle this,
95+
96+
```ParallelAppium::ParallelAppium.new.start platform: platform, file_path: file_path```
97+
98+
where platform is either android, ios or all and file_path is the absolute path to the folder or spec file
99+
to be executed.
100+
101+
### Initializing the appium instance(s)
102+
103+
As expected each appium instance will need to be loaded with capabilities defining all kinds of important things
104+
about how the tests executing on that instance will work, hence this will need to be done before the tests begin
105+
it's best to put this in some form of 'before all' block that will execute it prior to all the tests executing.
106+
107+
The following line of code is an example of what you'll need to use
108+
109+
```ParallelAppium::ParallelAppium.new.initialize_appium platform: ENV['platform']```
110+
111+
The initialize_appium function can take two parameters
112+
113+
1. platform - If provided it will look for a appium-{platform}.txt file in the root of the project and load capabilities
114+
from that location.
115+
2. caps - The capabilities as a map to be loaded.
116+
117+
### Setting UDID for the test
118+
119+
When distributing tests across multiple devices the library spreads the specs across multiple threads and depends on the
120+
UDID environment variable to know which device it's working with for the specific test file, as such this will need to
121+
be setup in each test file, simply include the following line of code at the top of the test file after any dependencies
122+
and the library will set this up as needed,
123+
124+
```ParallelAppium::Server.new.set_udid_environment_variable```
125+
126+
This is all you need to get started with this library. There's a number of environment variables set by the library
127+
for the purpose of writing easier cross platform tests. These are described in more detail below.
128+
129+
130+
--------
131+
132+
Next you'll need to ensure the project the respective appium text files for the platform,
133+
the gem will be looking for these files in the Project root. This file is used to load the capabilities of the driver
134+
at launch.
135+
136+
Here's examples of what both could look like
137+
138+
### appium-ios.txt
139+
140+
```
141+
[caps]
142+
platformName = "ios"
143+
deviceName = "iPhone Simulator"
144+
platformVersion = "11.4"
145+
app = "./apps/WordPress.app.zip"
146+
automationName = "XCUITest"
147+
bundleId = "org.wordpress"
148+
149+
[appium_lib]
150+
wait = 2
151+
```
152+
153+
### appium-android.txt
154+
155+
```
156+
[caps]
157+
platformName = "android"
158+
deviceName = "Android Emulator"
159+
platformVersion = "8.1.0"
160+
app = "./apps/WordPress.apk"
161+
appActivity = "org.wordpress.android.ui.WPLaunchActivity"
162+
appPackage = "org.wordpress.android"
163+
164+
[appium_lib]
165+
wait = 2
166+
```
167+
168+
The vales are expected to change to tailor to the host machine.
169+
170+
### Environment variables
171+
172+
173+
### Tags
174+
175+
24176

25177
## Development
26178

Rakefile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,39 @@ require 'rspec/core/rake_task'
44
RSpec::Core::RakeTask.new(:spec)
55

66
task default: :spec
7+
8+
# TODO: Move checks into gem
9+
namespace :parallel_appium do
10+
desc 'Validate Android'
11+
task :validate_android do
12+
%x(which emulator 2>&1)
13+
puts '==========================================='
14+
can_do_android = true
15+
can_do_android = can_do_android && ($? == 0)
16+
if can_do_android
17+
puts "emulator command configured properly"
18+
else
19+
puts "emulator command not configured properly"
20+
exit
21+
end
22+
puts '==========================================='
23+
puts 'Android good to go'
24+
end
25+
26+
desc 'Validate iOS'
27+
task :validate_ios do
28+
%x(which instruments 2>&1)
29+
puts '==========================================='
30+
can_do_ios = true
31+
can_do_ios = can_do_ios && ($? == 0)
32+
if can_do_ios
33+
puts "instruments command configured properly"
34+
else
35+
puts "instruments command not configured properly"
36+
exit
37+
end
38+
39+
puts '==========================================='
40+
puts 'iOS good to go'
41+
end
42+
end

apps/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

lib/parallel_appium.rb

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ def load_capabilities(caps)
3232
caps[:caps][:wdaLocalPort] = device.fetch('wdaPort', nil)
3333
end
3434

35-
caps[:caps][:sessionOverride] = true
36-
caps[:caps][:useNewWDA] = true
37-
# TODO: Optionally set these capabilities below
38-
caps[:caps][:noReset] = true
39-
caps[:caps][:fullReset] = false
4035
caps[:appium_lib][:server_url] = ENV['SERVER_URL']
4136
caps
4237
end
@@ -61,9 +56,11 @@ def initialize_appium(**args)
6156
puts 'No capabilities specified'
6257
exit
6358
end
59+
puts 'Preparing to load capabilities'
6460
capabilities = load_capabilities(caps)
61+
puts 'Loaded capabilities'
6562
@driver = Appium::Driver.new(capabilities, true)
66-
@driver.start_driver
63+
puts 'Created driver'
6764
Appium.promote_appium_methods Object
6865
Appium.promote_appium_methods RSpec::Core::ExampleGroup
6966
@driver
@@ -91,9 +88,9 @@ def setup_signal_handler(ios_pid = nil, android_pid = nil)
9188
# @param [boolean] parallel
9289
def execute_specs(platform, threads, spec_path, parallel = false)
9390
command = if parallel
94-
"platform=#{platform} parallel_rspec -n #{threads} #{spec_path} > output/#{platform}.log"
91+
"platform=#{platform} parallel_rspec -n #{threads} #{spec_path}"
9592
else
96-
"platform=#{platform} rspec #{spec_path} --tag #{platform} > output/#{platform}.log"
93+
"platform=#{platform} rspec #{spec_path} --tag #{platform}"
9794
end
9895

9996
puts "Executing #{command}"

lib/parallel_appium/ios.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ def initialize
99

1010
# Filter simulator data
1111
def simulator_information
12-
re = /\([0-9]+\.[0-9]\) \[[0-9A-Z-]+\]/m
12+
re = /\([0-9]+\.[0-9](\.[0-9])?\) \[[0-9A-Z-]+\]/m
1313

1414
# Filter out simulator info for iPhone platform version and udid
1515
@simulators.select { |simulator_data| simulator_data.include?('iPhone') && !simulator_data.include?('Apple Watch') }
16-
.map { |simulator_data| simulator_data.scan(re)[0].tr('()[]', '').split }[0, ENV['THREADS'].to_i]
16+
.map { |simulator_data| simulator_data.match(re).to_s.tr('()[]', '').split }[0, ENV['THREADS'].to_i]
1717
end
1818

1919
# Devices after cleanup and supplemental data included
@@ -28,3 +28,4 @@ def devices
2828
end
2929
end
3030
end
31+

lib/parallel_appium/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module ParallelAppium
2-
VERSION = '0.2.0'.freeze
2+
VERSION = '0.2.5'.freeze
33
end

parallel_appium.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ lib = File.expand_path('lib', __dir__)
33
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
44
require 'parallel_appium/version'
55

6-
summary = 'Start multi-threaded appium servers'
6+
summary = 'Multi-threaded mobile testing with Appium, Selenium and Rspec'
77
description = 'Through the creation of multiple environments
88
this library allows for the distribution of multiple tests across 1 or more
99
devices or simulators. The library uses Selenium Grid and Appium to launch a
10-
specified number of web driver and appium instances to spread the test load
10+
specified number of web driver and appium instances to distribute the RSpec test load
1111
across available devices'
1212

1313
Gem::Specification.new do |spec|

0 commit comments

Comments
 (0)