Skip to content
Open
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 Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ gem 'browserstack-local'
gem 'parallel_tests'
gem 'browserstack-automate'
gem 'rake'
gem 'browserstack-ruby-sdk'
47 changes: 32 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,43 @@
cucumber-browserstack
=====================
![BrowserStack Logo](https://d98b8t1nnulk5.cloudfront.net/production/images/layout/logo-header.png?1469004780)

This repository provides information and helpful tweaks to run your Cucumber tests on the BrowserStack selenium cloud infrastructure.
Code samples to get started with Cucumber tests on BrowserStack Automate using the **BrowserStack Ruby SDK**.

## Setup
* Clone the repo
* Install dependencies `bundle install`
* To test various sample repositories with ease, it is recommended to setup `BROWSERSTACK_USERNAME` and `BROWSERSTACK_ACCESS_KEY` environment variables. Alternatively you can directly update `*.config.yml` files inside the `config/` directory with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings)

### Running your tests
* To run tests, run `bundle exec rake parallel`
* To run local tests, run `bundle exec rake local`
### Requirements

Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github)
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 don't have Bundler installed, follow the instructions given [here](https://bundler.io/)

Alternatively the variables can be set in the environment using env or your CI framework (like Travis or Jenkins)
### Install the dependencies

Notice that selenium driver.quit is not required for Capybara tests because Capybara implicitly does so.
```sh
bundle install
```

###Further Reading
- [Cucumber](https://cucumber.io/)
- [CapyBara](http://jnicklas.github.io/capybara/)
- [BrowserStack documentation for Automate](https://www.browserstack.com/automate/ruby)
---

Happy Testing!
## Configuration

### 1. Set up `browserstack.yml`

All BrowserStack configuration is managed through a single `browserstack.yml` file at the root of the repository.

Set parallels.

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

## Running your tests

All tests are run from the repo root. The same command is used for all run types — behaviour is controlled entirely by `browserstack.yml`:

```sh
bundle exec browserstack-sdk exec cucumber features/sample.feature
```

> **Tip:** Instead of hardcoding credentials, set `BROWSERSTACK_USERNAME` and `BROWSERSTACK_ACCESS_KEY` as environment variables.

### 2.
26 changes: 0 additions & 26 deletions Rakefile

This file was deleted.

29 changes: 29 additions & 0 deletions browserstack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
userName: YOUR_BROWSERSTACK_USERNAME # or use BROWSERSTACK_USERNAME env var
accessKey: YOUR_BROWSERSTACK_ACCESS_KEY # or use BROWSERSTACK_ACCESS_KEY env var

projectName: BStack cucumber-ruby
buildName: browserstack-build-1

browsers:
- browserName: chrome
browserVersion: latest
os: Windows
osVersion: 11
- browserName: firefox
browserVersion: latest
os: Windows
osVersion: 11
- browserName: edge
browserVersion: latest
os: Windows
osVersion: 11
- browserName: safari
browserVersion: latest
os: OS X
osVersion: Ventura

debug: true

parallelsPerPlatform: 1

browserStackLocal: false # set to true for local testing
14 changes: 0 additions & 14 deletions config/local.config.yml

This file was deleted.

15 changes: 0 additions & 15 deletions config/parallel.config.yml

This file was deleted.

12 changes: 0 additions & 12 deletions config/single.config.yml

This file was deleted.

27 changes: 4 additions & 23 deletions features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'selenium/webdriver'
require 'capybara/cucumber'
require 'browserstack/local'
require 'browserstack/sdk'

# monkey patch to avoid reset sessions
class Capybara::Selenium::Driver < Capybara::Driver::Base
Expand All @@ -10,32 +11,12 @@ def reset!
end
end

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

CONFIG = YAML.safe_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']

Capybara.register_driver :browserstack do |app|
@caps = CONFIG['common_caps'].merge(CONFIG['browser_caps'][TASK_ID])
# Code to start browserstack local before start of test
if @caps['browserstack.local'] && @caps['browserstack.local'].to_s == 'true'
@bs_local = BrowserStack::Local.new
bs_local_args = { 'key' => (CONFIG['key']).to_s }
@bs_local.start(bs_local_args)
end

Capybara::Selenium::Driver.new(app,
browser: :remote,
url: "https://#{CONFIG['user']}:#{CONFIG['key']}@#{CONFIG['server']}/wd/hub",
desired_capabilities: @caps)
browser: :remote,
url: "https://hub.browserstack.com/wd/hub")
# SDK injects credentials, browser caps, build, project, local, etc. automatically
end

Capybara.default_driver = :browserstack
Capybara.run_server = false

# Code to stop browserstack local after end of test
at_exit do
@bs_local.stop unless @bs_local.nil?
end