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
93 changes: 72 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,107 @@
cucumber-ruby-app-browserstack
=====================
![BrowserStack Logo](https://d98b8t1nnulk5.cloudfront.net/production/images/layout/logo-header.png?1469004780)
![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.
Code samples to get started with Appium tests for your Native App using the Cucumber framework on BrowserStack, using the **BrowserStack Ruby SDK**.

## Setup

### Requirements

1. Ruby: If you don't have Ruby installed, follow the instructions given [here](https://www.ruby-lang.org/en/documentation/installation/)
2. Bundler : If you dont have Bundler installed, follow the instructions given [here](https://bundler.io/)
2. Bundler: If you don't have Bundler installed, follow the instructions given [here](https://bundler.io/)

### Install the dependencies

To install the dependencies for Android tests, run :
To install the dependencies for Android tests, run:
```sh
cd android/examples
bundle install
```

Or,

To install the dependencies for iOS tests, run :

Or, to install the dependencies for iOS tests, run:
```sh
cd ios/examples
bundle install
```

---

## Configuration

### Set up `browserstack.yml`

All BrowserStack configuration is managed through a single `browserstack.yml` file located at `android/examples/browserstack.yml`.

```yaml
userName: YOUR_BROWSERSTACK_USERNAME # or set BROWSERSTACK_USERNAME env var
accessKey: YOUR_BROWSERSTACK_ACCESS_KEY # or set BROWSERSTACK_ACCESS_KEY env var

app: bs://<app-id> # or set BROWSERSTACK_APP_ID env var

projectName: First Cucumber Android Project
buildName: browserstack-build-1

platforms:
- deviceName: Google Pixel 8 Pro
osVersion: "14.0"
platformName: android

debug: true

browserStackLocal: false # set to true for local testing
```


### For local testing

Set `browserStackLocal: true` in `browserstack.yml`.

```yaml
browserStackLocal: true
```

---

## Getting Started

Getting Started with Appium tests in Cucumber Ruby on BrowserStack couldn't be easier!
All tests are run from the `android/examples/` directory using the `browserstack-sdk exec` CLI.

### **Run first test:**

```sh
cd android/examples
bundle exec browserstack-sdk exec cucumber run-first-test/features
```

### **Run parallel tests:**

### **Run first test :**
Ensure `platforms:` in `browserstack.yml` has multiple device entries, then run:

- Switch to `run_first_test` directory under [Android examples](android/examples) or [iOS examples](ios/examples)
- Follow the steps outlined in the documentation - [Get Started with your first test on App Automate](https://www.browserstack.com/docs/app-automate/appium/getting-started/ruby/cucumber)
```sh
cd android/examples
bundle exec browserstack-sdk exec cucumber run-parallel-tests/features
```

### **Speed up test execution with parallel testing :**
### **Run local test:**

- Switch to `run_parallel_test` directory under [Android examples](android/examples/) or [iOS examples](ios/examples/)
- Follow the steps outlined in the documentation - [Get Started with parallel testing on App Automate](https://www.browserstack.com/docs/app-automate/appium/getting-started/ruby/cucumber/local-testing)
Ensure `browserStackLocal: true` is set in `browserstack.yml`, then run:

### **Use Local testing for apps that access resources hosted in development or testing environments :**
```sh
cd android/examples
bundle exec browserstack-sdk exec cucumber run-local-test/features
```

- Switch to `run_local_test` directory under [Android examples](android/examples/) or [iOS examples](ios/examples/)
- Follow the steps outlined in the documentation - [Get Started with Local testing on App Automate](https://www.browserstack.com/docs/app-automate/appium/getting-started/ruby/cucumber/local-testing)
---

## Getting Help

If you are running into any issues or have any queries, please check [Browserstack Support page](https://www.browserstack.com/support/app-automate) or [get in touch with us](https://www.browserstack.com/contact?ref=help).
If you are running into any issues or have any queries, please check the [BrowserStack Support page](https://www.browserstack.com/support/app-automate) or [get in touch with us](https://www.browserstack.com/contact).

Note: For other test frameworks supported by App Automate, refer to our [Developer documentation](https://www.browserstack.com/docs/).

Note: For other test frameworks supported by App-Automate refer our [Developer documentation](https://www.browserstack.com/docs/)
## Additional Resources

## Addtional Resources
* [BrowserStack Ruby SDK](https://www.browserstack.com/docs/automate/selenium/sdk-config)
* [Cucumber](https://cucumber.io/)
* [Appium](https://appium.io/)
1 change: 1 addition & 0 deletions android/examples/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ gem 'rake'
gem 'browserstack-local'
gem 'parallel_tests'
gem 'appium_lib'
gem 'browserstack-ruby-sdk'
39 changes: 0 additions & 39 deletions android/examples/Rakefile

This file was deleted.

20 changes: 20 additions & 0 deletions android/examples/browserstack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
userName: YOUR_BROWSERSTACK_USERNAME
accessKey: YOUR_BROWSERSTACK_ACCESS_KEY

app: bs://<app-id>

projectName: First Cucumber Android Project
buildName: browserstack-build-1

platforms:
- deviceName: Google Pixel 8 Pro
osVersion: "14.0"
platformName: android
- deviceName: Samsung Galaxy S22 Ultra
osVersion: "12.0"
platformName: android

debug: true

browserStackLocal: false # Set to true if you want to test your private or internal server using BrowserStack Local
parallelsPerPlatform: 1 # Set value for parallel execution.
15 changes: 0 additions & 15 deletions android/examples/run-first-test/config/first.config.yml

This file was deleted.

19 changes: 2 additions & 17 deletions android/examples/run-first-test/features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,11 @@
require 'selenium-cucumber'
require 'browserstack/local'
require 'appium_lib'

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

CONFIG = YAML.load(File.read(File.join(File.dirname(__FILE__), "../../config/#{CONFIG_NAME}.config.yml")))

caps = CONFIG['common_caps'].merge(CONFIG['browser_caps'][TASK_ID])
caps['browserstack.user'] = ENV['BROWSERSTACK_USERNAME'] || caps['browserstack.user']
caps['browserstack.key'] = ENV['BROWSERSTACK_ACCESS_KEY'] || caps['browserstack.key']

$bs_local = nil

if ENV['BROWSERSTACK_APP_ID']
caps['app'] = ENV['BROWSERSTACK_APP_ID']
end
require 'browserstack/sdk'

desired_caps = {
caps: caps,
appium_lib: {
server_url: "http://#{CONFIG['server']}/wd/hub"
server_url: "http://hub.browserstack.com/wd/hub"
}
}

Expand Down
4 changes: 0 additions & 4 deletions android/examples/run-first-test/features/support/hooks.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
After do
$driver.quit if $driver
if $bs_local
$bs_local.stop
$bs_local = nil
end
end
16 changes: 0 additions & 16 deletions android/examples/run-local-test/config/local.config.yml

This file was deleted.

25 changes: 2 additions & 23 deletions android/examples/run-local-test/features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,11 @@
require 'selenium-cucumber'
require 'browserstack/local'
require 'appium_lib'

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

CONFIG = YAML.load(File.read(File.join(File.dirname(__FILE__), "../../config/#{CONFIG_NAME}.config.yml")))

caps = CONFIG['common_caps'].merge(CONFIG['browser_caps'][TASK_ID])
caps['browserstack.user'] = ENV['BROWSERSTACK_USERNAME'] || caps['browserstack.user']
caps['browserstack.key'] = ENV['BROWSERSTACK_ACCESS_KEY'] || caps['browserstack.key']

$bs_local = nil

if ENV['BROWSERSTACK_APP_ID']
caps['app'] = ENV['BROWSERSTACK_APP_ID']
end

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

desired_caps = {
caps: caps,
appium_lib: {
server_url: "http://#{CONFIG['server']}/wd/hub"
server_url: "http://hub.browserstack.com/wd/hub"
}
}

Expand Down
4 changes: 0 additions & 4 deletions android/examples/run-local-test/features/support/hooks.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
After do
$driver.quit if $driver
if $bs_local
$bs_local.stop
$bs_local = nil
end
end
19 changes: 0 additions & 19 deletions android/examples/run-parallel-tests/config/parallel.config.yml

This file was deleted.

19 changes: 2 additions & 17 deletions android/examples/run-parallel-tests/features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,11 @@
require 'selenium-cucumber'
require 'browserstack/local'
require 'appium_lib'

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

CONFIG = YAML.load(File.read(File.join(File.dirname(__FILE__), "../../config/#{CONFIG_NAME}.config.yml")))

caps = CONFIG['common_caps'].merge(CONFIG['browser_caps'][TASK_ID])
caps['browserstack.user'] = ENV['BROWSERSTACK_USERNAME'] || caps['browserstack.user']
caps['browserstack.key'] = ENV['BROWSERSTACK_ACCESS_KEY'] || caps['browserstack.key']

$bs_local = nil

if ENV['BROWSERSTACK_APP_ID']
caps['app'] = ENV['BROWSERSTACK_APP_ID']
end
require 'browserstack/sdk'

desired_caps = {
caps: caps,
appium_lib: {
server_url: "http://#{CONFIG['server']}/wd/hub"
server_url: "http://hub.browserstack.com/wd/hub"
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
After do
$driver.quit if $driver
if $bs_local
$bs_local.stop
$bs_local = nil
end
end
Loading
Loading