Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
local.log
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
# cucumber-ruby-appium-app-browserstack
cucumber-ruby-app-browserstack
=====================
![BrowserStack Logo](https://d98b8t1nnulk5.cloudfront.net/production/images/layout/logo-header.png?1469004780)

Code samples to get started with Appium tests for your Native App using the Cucumber framework.

## Resources
* [Get Started guide](https://www.browserstack.com/app-automate/appium-cucumber)
* [Android sample code repo](https://github.com/browserstack/cucumber-ruby-appium-app-browserstack/tree/master/android)
* [IOS sample code repo](https://github.com/browserstack/cucumber-ruby-appium-app-browserstack/tree/master/ios)
10 changes: 10 additions & 0 deletions android/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
source 'http://rubygems.org'

gem 'cucumber'
gem 'selenium-cucumber'
gem 'selenium-webdriver'
gem 'rspec'
gem 'rake'
gem 'browserstack-local'
gem 'parallel_tests'
gem 'appium_lib'
86 changes: 86 additions & 0 deletions android/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
GEM
remote: http://rubygems.org/
specs:
appium_lib (9.7.1)
awesome_print (~> 1.8)
json (>= 1.8)
nokogiri (~> 1.6, >= 1.6.6)
selenium-webdriver (~> 3.4, >= 3.4.1)
tomlrb (~> 1.1)
awesome_print (1.8.0)
backports (3.8.0)
browserstack-local (1.3.0)
builder (3.2.3)
childprocess (0.8.0)
ffi (~> 1.0, >= 1.0.11)
chunky_png (1.3.8)
cucumber (3.0.1)
builder (>= 2.1.2)
cucumber-core (~> 3.0.0)
cucumber-expressions (~> 4.0.3)
cucumber-wire (~> 0.0.1)
diff-lcs (~> 1.3)
gherkin (~> 4.0)
multi_json (>= 1.7.5, < 2.0)
multi_test (>= 0.1.2)
cucumber-core (3.0.0)
backports (>= 3.8.0)
cucumber-tag_expressions (>= 1.0.1)
gherkin (>= 4.1.3)
cucumber-expressions (4.0.4)
cucumber-tag_expressions (1.0.1)
cucumber-wire (0.0.1)
diff-lcs (1.3)
ffi (1.9.18)
gherkin (4.1.3)
json (2.1.0)
mini_portile2 (2.3.0)
multi_json (1.12.2)
multi_test (0.1.2)
nokogiri (1.8.1)
mini_portile2 (~> 2.3.0)
parallel (1.12.0)
parallel_tests (2.17.0)
parallel
rake (12.0.0)
rspec (3.6.0)
rspec-core (~> 3.6.0)
rspec-expectations (~> 3.6.0)
rspec-mocks (~> 3.6.0)
rspec-core (3.6.0)
rspec-support (~> 3.6.0)
rspec-expectations (3.6.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.6.0)
rspec-mocks (3.6.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.6.0)
rspec-support (3.6.0)
rubyzip (1.2.1)
selenium-cucumber (3.1.5)
appium_lib (>= 8.0.2)
chunky_png (>= 1.3.5)
cucumber (>= 2.3.0)
rspec (>= 3.4.0)
selenium-webdriver (>= 2.53.0)
selenium-webdriver (3.6.0)
childprocess (~> 0.5)
rubyzip (~> 1.0)
tomlrb (1.2.5)

PLATFORMS
ruby
x86_64-darwin-16

DEPENDENCIES
appium_lib
browserstack-local
cucumber
parallel_tests
rake
rspec
selenium-cucumber
selenium-webdriver

BUNDLED WITH
1.15.3
33 changes: 33 additions & 0 deletions android/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## Setup
* Clone the repo
* Install dependencies `bundle install`
* Update `.config.yml` files inside the `config` directory with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings).

## Running your tests
* Upload your Native App (.apk file) to BrowserStack servers using upload API:

```
curl -u "username:accesskey" -X POST "https://api.browserstack.com/app-automate/upload" -F "file=@/path/to/app/file/Application-debug.apk"
```

* If you do not have an .apk file and looking to simply try App Automate, [you can download our sample app and upload](https://www.browserstack.com/app-automate/sample-apps/android/WikipediaSample.apk)
to the BrowserStack servers using the above API.
* For running local tests, you can use our [local sample app](https://www.browserstack.com/app-automate/sample-apps/android/LocalSample.apk).
* Update the desired capability "app" with the App URL returned from the above API call
* To run a single test, run `bundle exec rake single`
* To run parallel tests, run `bundle exec rake parallel`
* To run local tests, run `bundle exec rake local`

## Notes
* You can view your test results on the [BrowserStack Automate dashboard](https://www.browserstack.com/app-automate)
* Refer [Get Started](https://www.browserstack.com/app-automate/appium-cucumber) document to configure the capabilities
* You can export the environment variables for the Username and Access Key of your BrowserStack account.

```
export BROWSERSTACK_USERNAME=<browserstack-username> &&
export BROWSERSTACK_ACCESS_KEY=<browserstack-access-key>
```

## Addtional Resources
* [Cucumber](https://cucumber.io/)
* [Getting Started with App Automate](https://www.browserstack.com/app-automate/appium-cucumber)
35 changes: 35 additions & 0 deletions android/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'rake'
require 'parallel'
require 'cucumber/rake/task'

Cucumber::Rake::Task.new(:single) do |task|
ENV['CONFIG_NAME'] ||= "single"
task.cucumber_opts = ['--format=pretty', 'features/single.feature']
end

task :default => :single

Cucumber::Rake::Task.new(:local) do |task|
task.cucumber_opts = ['--format=pretty', 'features/local.feature', 'CONFIG_NAME=local']
end

task :parallel do |t, args|
@num_parallel = 4

Parallel.map([*1..@num_parallel], :in_processes => @num_parallel) do |task_id|
ENV["TASK_ID"] = (task_id - 1).to_s
ENV['name'] = "parallel_test"
ENV['CONFIG_NAME'] = "parallel"

Rake::Task["single"].invoke
Rake::Task["single"].reenable
end
end


task :test do |t, args|
Rake::Task["single"].invoke
Rake::Task["single"].reenable
Rake::Task["local"].invoke
Rake::Task["parallel"].invoke
end
15 changes: 15 additions & 0 deletions android/config/local.config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
server: "hub.browserstack.com"
user: "BROWSERSTACK_USERNAME"
key: "BROWSERSTACK_ACCESS_KEY"

common_caps:
"build": "cucumber-browserstack"
"browserstack.debug": true

browser_caps:
-
"device": "Google Pixel"
"realMobile": true
"app": "bs://<hashed app-id>"
"browserstack.local": true
"name": "local_test"
24 changes: 24 additions & 0 deletions android/config/parallel.config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
server: "hub.browserstack.com"
user: "BROWSERSTACK_USERNAME"
key: "BROWSERSTACK_ACCESS_KEY"

common_caps:
"build": "cucumber-browserstack"
"browserstack.debug": true

browser_caps:
-
"device": "Google Pixel"
"realMobile": true
"app": "bs://<hashed app-id>"
"name": "parallel_test"
-
"device": "Google Nexus 5"
"realMobile": true
"app": "bs://<hashed app-id>"
"name": "parallel_test"
-
"device": "Samsung Galaxy S7"
"realMobile": true
"app": "bs://<hashed app-id>"
"name": "parallel_test"
14 changes: 14 additions & 0 deletions android/config/single.config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
server: "hub.browserstack.com"
user: "BROWSERSTACK_USERNAME"
key: "BROWSERSTACK_ACCESS_KEY"

common_caps:
"build": "cucumber-browserstack"
"browserstack.debug": true

browser_caps:
-
"device": "Google Pixel"
"realMobile": true
"app": "bs://<hashed app-id>"
"name": "single_test"
7 changes: 7 additions & 0 deletions android/features/local.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Feature: BrowserStack Local Testing

Background:
Given I start test on the Local Sample App

Scenario: Can check tunnel working
Then I should see "Up and running"
8 changes: 8 additions & 0 deletions android/features/single.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Feature: Search in Wikipedia App

Background:
Given I try to search using Wikipedia App

Scenario: Search for a term
When I type in "BrowserStack"
Then I should see results
13 changes: 13 additions & 0 deletions android/features/step_definitions/local_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
When /^I start test on the Local Sample App/ do
$wait.until { $driver.find_element(:id, "com.example.android.basicnetworking:id/test_action").displayed? }
$driver.find_element(:id, "com.example.android.basicnetworking:id/test_action").click
end

Then("I should see {string}") do |match_string|
$wait.until { $driver.find_element(:class, "android.widget.TextView").displayed? }
text_elements = $driver.find_elements(:class, "android.widget.TextView")
local_text_element = text_elements.select { |each_element| each_element.text.match(/The active connection is/) }
local_text = local_text_element.first.text
local_text.should include("The active connection is wifi.")
local_text.should include("Up and running")
end
15 changes: 15 additions & 0 deletions android/features/step_definitions/single_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
When /^I try to search using Wikipedia App/ do
$wait.until { $driver.find_element(:accessibility_id, "Search Wikipedia").displayed? }
$driver.find_element(:accessibility_id, "Search Wikipedia").click
end

When("I type in {string}") do |search_keyword|
$wait.until { $driver.find_element(:id, "org.wikipedia.alpha:id/search_src_text").displayed? }
search_box = $driver.find_element(:id, "org.wikipedia.alpha:id/search_src_text")
search_box.send_key(search_keyword)
sleep 5
end

Then /^I should see results$/ do
$driver.find_elements(:class, "android.widget.TextView").size.should > 0
end
38 changes: 38 additions & 0 deletions android/features/support/env.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require 'yaml'
require 'rspec'
require 'selenium-cucumber'
require 'browserstack/local'
require 'appium_lib'

TASK_ID = (ENV['TASK_ID'] || 0).to_i
CONFIG_NAME = ENV['CONFIG_NAME'] || 'single'

CONFIG = YAML.load(File.read(File.join(File.dirname(__FILE__), "../../config/#{CONFIG_NAME}.config.yml")))
CONFIG['user'] = ENV['BROWSERSTACK_USERNAME'] || CONFIG['user']
CONFIG['key'] = ENV['BROWSERSTACK_ACCESS_KEY'] || CONFIG['key']

caps = CONFIG['common_caps'].merge(CONFIG['browser_caps'][TASK_ID])
$bs_local = nil

if caps['browserstack.local'] && caps['browserstack.local'].to_s == 'true'
$bs_local = BrowserStack::Local.new
bs_local_args = { "key" => "#{CONFIG['key']}" }
$bs_local.start(bs_local_args)
end

desired_caps = {
caps: caps,
appium_lib: {
server_url: "http://#{CONFIG['user']}:#{CONFIG['key']}@#{CONFIG['server']}/wd/hub"
}
}

begin
$appium_driver = Appium::Driver.new(desired_caps, true)
$driver = $appium_driver.start_driver
rescue Exception => e
puts e.message
Process.exit(0)
end

$wait = Selenium::WebDriver::Wait.new(:timeout => 30)
7 changes: 7 additions & 0 deletions android/features/support/hooks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
After do
$driver.quit if $driver
if $bs_local
$bs_local.stop
$bs_local = nil
end
end
10 changes: 10 additions & 0 deletions ios/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
source 'http://rubygems.org'

gem 'cucumber'
gem 'selenium-cucumber'
gem 'selenium-webdriver'
gem 'rspec'
gem 'rake'
gem 'browserstack-local'
gem 'parallel_tests'
gem 'appium_lib'
Loading