Skip to content

Patch 1 #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 29 commits into
base: new_sample_app
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
bb5f35d
Merge pull request #6 from browserstack/new_sample_app
agundawar May 14, 2018
d067e59
Updating First test for Android and iOS
kn-neeraj Aug 25, 2020
d6dc94e
Adding 'platformName' capability
kn-neeraj Aug 25, 2020
9bb2285
Adding Ruby bundler and updating Readme
kn-neeraj Aug 25, 2020
8ca501c
Updating gemfile
kn-neeraj Aug 25, 2020
17e62f8
Updating test class names
kn-neeraj Aug 26, 2020
06919c6
Removing unwanted Readmes
kn-neeraj Aug 26, 2020
90c24ba
Update README.md
kn-neeraj Aug 26, 2020
783d1d4
Adding specific versions for dependencies. Updated Readme
kn-neeraj Aug 31, 2020
7d839de
Typo fixes
kn-neeraj Sep 1, 2020
176afd6
Updated local test script
kn-neeraj Sep 24, 2020
d5feb83
Updated readme
kn-neeraj Sep 25, 2020
8589894
Update README.md
kn-neeraj Sep 25, 2020
a52de62
Update README.md
kn-neeraj Sep 25, 2020
84d363d
Update README.md
kn-neeraj Sep 25, 2020
a1ef075
updating file names according to QSG
kn-neeraj Sep 26, 2020
d267bec
Updating Readme.
kn-neeraj Sep 26, 2020
e868768
Updating Readme.
kn-neeraj Sep 26, 2020
f729424
Adding workaround for Windows in Ruby
kn-neeraj Oct 1, 2020
dba1f18
BrowserStack access credentials URL in readme.
kn-neeraj Oct 1, 2020
df112c4
Merge pull request #7 from kn-neeraj/qsg-firsttest-changes
agundawar Oct 7, 2020
5c9d964
Bump faye-websocket from 0.10.9 to 0.11.0
dependabot[bot] Oct 7, 2020
7ca2d47
Merge pull request #8 from browserstack/dependabot/bundler/faye-webso…
agundawar Oct 13, 2020
90d0636
fixed readme
rishav-csenitjsr Oct 13, 2020
ecc23bd
removed support for lower version
rishav-csenitjsr Oct 13, 2020
b6ba8f2
Merge pull request #9 from rishav-csenitjsr/fix_readme
agundawar Oct 13, 2020
6c39919
Updated build names as per QIG
nitish-bhardwaj-code Sep 20, 2021
f5130cc
Merge pull request #10 from nitish-bhardwaj-code/update_build_name
deepwired Sep 29, 2021
56329e2
Update browserstack_sample.rb
lonayman Aug 30, 2022
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
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'http://rubygems.org'

gem 'appium_lib', ">=10.5.0"
gem 'browserstack-local', ">=1.3.0"
37 changes: 37 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
GEM
remote: http://rubygems.org/
specs:
appium_lib (10.6.0)
appium_lib_core (~> 3.3)
nokogiri (~> 1.8, >= 1.8.1)
tomlrb (~> 1.1)
appium_lib_core (3.11.0)
faye-websocket (~> 0.11.0)
selenium-webdriver (~> 3.14, >= 3.14.1)
browserstack-local (1.3.0)
childprocess (3.0.0)
eventmachine (1.2.7)
faye-websocket (0.11.0)
eventmachine (>= 0.12.0)
websocket-driver (>= 0.5.1)
mini_portile2 (2.4.0)
nokogiri (1.10.10)
mini_portile2 (~> 2.4.0)
rubyzip (2.3.0)
selenium-webdriver (3.142.7)
childprocess (>= 0.5, < 4.0)
rubyzip (>= 1.2.2)
tomlrb (1.3.0)
websocket-driver (0.7.3)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)

PLATFORMS
ruby

DEPENDENCIES
appium_lib (>= 10.5.0)
browserstack-local (>= 1.3.0)

BUNDLED WITH
2.1.4
114 changes: 110 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,115 @@
# ruby-appium-app-browserstack
App Automate Ruby Samples
---------------------

This repository contains code for Automated Native App tests. Please feel free to clone the repo and use the example code.
This repository demonstrates how to run Appium Ruby tests on BrowserStack App Automate.

For frameworks integration with BrowserStack, refer to their individual repositories -
## Setup

### Requirements

1. Ruby >=2.6

- If not installed, install Ruby from [here](https://www.ruby-lang.org/en/documentation/installation/)

2. Dependency Manager `bundler`

- If not installed, run command `gem install bundler`

### Install the dependencies

To install the dependencies, run the following command in the project's base directory :

```ruby
bundle install
```

**Note**: If you are using Windows, RubyInstaller has a known [issue](https://github.com/oneclick/rubyinstaller2/issues/96). Run the following script as a workaround to resolve it -

```ruby
gem install ffi
gem uninstall -aIx eventmachine
gem install eventmachine --platform=ruby
```

## Getting Started

Getting Started with Appium tests in Ruby on BrowserStack couldn't be easier!

### Run your first test :

**1. Upload your Android or iOS App**
Upload your Android app (.apk or .aab file) or iOS app (.ipa file) to BrowserStack servers using our REST API. Here is an example cURL request :

```
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/upload" \
-F "file=@/path/to/apk/file"
```

Ensure that @ symbol is prepended to the file path in the above request. Please note the `app_url` value returned in the API response. We will use this to set the application under test while configuring the test later on.

**Note**: If you do not have an .apk or .ipa file and are looking to simply try App Automate, you can download and test using our [sample Android app](https://www.browserstack.com/app-automate/sample-apps/android/WikipediaSample.apk) or [sample iOS app](https://www.browserstack.com/app-automate/sample-apps/ios/BStackSampleApp.ipa).

**2. Configure and run your first test**

Open `browserstack_sample.rb` file in `android` or `ios` directory :

- Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials. Get your BrowserStack access credentials from [here](https://www.browserstack.com/accounts/settings)

- Replace `bs://<app-id>` wkth the URL obtained from app upload step

- Set the device and OS version

- If you have uploaded your own app update the test case

- Run `ruby browserstack_sample.rb`

- You can access the test execution results, and debugging information such as video recording, network logs on [App Automate dashboard](https://app-automate.browserstack.com/dashboard)

---

### Use Local testing for apps that access resources hosted in development or testing environments :

**1. Upload your Android or iOS App**

Upload your Android app (.apk or .aab file) or iOS app (.ipa file) that access resources hosted on your internal or test environments to BrowserStack servers using our REST API. Here is an example cURL request :

```
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/upload" \
-F "file=@/path/to/apk/file"
```

Ensure that @ symbol is prepended to the file path in the above request. Please note the `app_url` value returned in the API response. We will use this to set the application under test while configuring the test later on.

**Note**: If you do not have an .apk or .ipa file and are looking to simply try App Automate, you can download and test using our [sample Android Local app](https://www.browserstack.com/app-automate/sample-apps/android/LocalSample.apk) or [sample iOS Local app](https://www.browserstack.com/app-automate/sample-apps/ios/LocalSample.ipa).


**2. Configure and run your local test**

Open `browserstack_sample_local.rb` file in `android` or `ios` directory :

- Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials. Get your BrowserStack access credentials from [here](https://www.browserstack.com/accounts/settings)

- Replace `bs://<app-id>` wkth the URL obtained from app upload step

- Set the device and OS version

- Ensure that `browserstack.local` capability is set to `true`. Within the test script, there is code snippet that automatically establishes Local Testing connection to BrowserStack servers using Ruby binding for BrowserStack Local.

- If you have uploaded your own app update the test case

- Run `ruby browserstack_sample_local.rb`

- You can access the test execution results, and debugging information such as video recording, network logs on [App Automate dashboard](https://app-automate.browserstack.com/dashboard)

## Integration with other frameworks

For other Ruby frameworks samples, refer to following repositories :

- [Cucumber](https://github.com/browserstack/cucumber-ruby-appium-app-browserstack)

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

## 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).
28 changes: 0 additions & 28 deletions android/README.md

This file was deleted.

32 changes: 23 additions & 9 deletions android/single_test.rb → android/browserstack_sample.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
require 'rubygems'
Derequire 'rubygems'
require 'appium_lib'
require 'selenium-webdriver'

username = 'BROWSERSTACK_USERNAME'
access_key = 'BROWSERSTACK_ACCESS_KEY'

caps = {}
caps['build'] = 'Ruby Appium Sample'
# Set your access credentials
caps['browserstack.user'] = 'ysmnturut_aqNVOR'
caps['browserstack.key'] = 'n8WqPYcXQNBwiDmi8K8H'

# Set URL of the application under test
caps['app'] = 'bs://<app-id>'

# Specify device and os_version for testing
caps['device'] = 'Google Pixel 3'
caps['os_version'] = '9.0'

# Set other BrowserStack capabilities
caps['project'] = 'First Ruby project'
caps['build'] = 'browserstack-build-1'
caps['name'] = 'single_test'
caps['device'] = 'Google Pixel'

#Set the platform name
caps['platformName'] = 'android'
caps['browserstack.debug'] = true
caps['app'] = 'bs://<hashed app-id>'

# Initialize the remote Webdriver using BrowserStack remote URL
# and desired capabilities defined above
appium_driver = Appium::Driver.new({
'caps' => caps,
'appium_lib' => {
:server_url => "http://#{username}:#{access_key}@hub-cloud.browserstack.com/wd/hub"
:server_url => "http://hub-cloud.browserstack.com/wd/hub"
}}, true)
driver = appium_driver.start_driver

# Test case for the BrowserStack sample Android app.
# If you have uploaded your app, update the test case here.
wait = Selenium::WebDriver::Wait.new(:timeout => 30)
wait.until { driver.find_element(:accessibility_id, "Search Wikipedia").displayed? }
element = driver.find_element(:accessibility_id, "Search Wikipedia")
Expand All @@ -37,4 +50,5 @@
puts "No results found - Test Failed"
end

# Invoke driver.quit() after the test is done to indicate that the test is completed.
driver.quit
34 changes: 27 additions & 7 deletions android/local_test.rb → android/browserstack_sample_local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,47 @@
require 'selenium-webdriver'
require 'browserstack/local'

username = 'BROWSERSTACK_USERNAME'
access_key = 'BROWSERSTACK_ACCESS_KEY'
username = 'YOUR_USERNAME'
access_key = 'YOUR_ACCESS_KEY'

caps = {}
caps['build'] = 'Ruby Appium Sample'
# Set your access credentials
caps['browserstack.user'] = username
caps['browserstack.key'] = access_key

# Set URL of the application under test
caps['app'] = 'bs://<app-id>'

# Specify device and os_version for testing
caps['device'] = 'Google Pixel 3'
caps['os_version'] = '9.0'

# Set browserstack.local capability as true
caps['browserstack.local'] = true

# Set other BrowserStack capabilities
caps['project'] = 'First Ruby project'
caps['build'] = 'browserstack-build-1'
caps['name'] = 'local_test'
caps['device'] = 'Google Pixel'
caps['platformName'] = 'android'
caps['browserstack.local'] = true
caps['browserstack.debug'] = true
caps['app'] = 'bs://<hashed app-id>'

# Start browserstack local
bs_local = BrowserStack::Local.new
bs_local_args = { "key" => access_key }
bs_local.start(bs_local_args)

# Initialize the remote Webdriver using BrowserStack remote URL
# and desired capabilities defined above
appium_driver = Appium::Driver.new({
'caps' => caps,
'appium_lib' => {
:server_url => "http://#{username}:#{access_key}@hub-cloud.browserstack.com/wd/hub"
:server_url => "http://hub-cloud.browserstack.com/wd/hub"
}}, true)
driver = appium_driver.start_driver

# Test case for the BrowserStack sample Android app.
# If you have uploaded your app, update the test case here.
wait = Selenium::WebDriver::Wait.new(:timeout => 30)
wait.until { driver.find_element(:id, "com.example.android.basicnetworking:id/test_action").displayed? }
element = driver.find_element(:id, "com.example.android.basicnetworking:id/test_action")
Expand All @@ -40,5 +58,7 @@
puts "Local Testing setup not working - Test Failed"
end

# Invoke driver.quit() after the test is done to indicate that the test is completed.
driver.quit
# Stop browserstack local
bs_local.stop
28 changes: 0 additions & 28 deletions ios/README.md

This file was deleted.

30 changes: 22 additions & 8 deletions ios/single_test.rb → ios/browserstack_sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,37 @@
require 'appium_lib'
require 'selenium-webdriver'

username = 'BROWSERSTACK_USERNAME'
access_key = 'BROWSERSTACK_ACCESS_KEY'

caps = {}
caps['build'] = 'Ruby Appium Sample'
# Set your access credentials
caps['browserstack.user'] = 'YOUR_USERNAME'
caps['browserstack.key'] = 'YOUR_ACCESS_KEY'

# Set URL of the application under test
caps['app'] = 'bs://<app-id>'

# Specify device and os_version for testing
caps['device'] = "iPhone 11 Pro"
caps['os_version'] = "13"

# Set other BrowserStack capabilities
caps['project'] = 'First Ruby project'
caps['build'] = 'browserstack-build-1'
caps['name'] = 'single_test'
caps['device'] = 'iPhone 7 Plus'

#Set the platform name
caps['platformName'] = 'iOS'
caps['browserstack.debug'] = true
caps['app'] = 'bs://<hashed app-id>'

# Initialize the remote Webdriver using BrowserStack remote URL
# and desired capabilities defined above
appium_driver = Appium::Driver.new({
'caps' => caps,
'appium_lib' => {
:server_url => "http://#{username}:#{access_key}@hub-cloud.browserstack.com/wd/hub"
:server_url => "http://hub-cloud.browserstack.com/wd/hub"
}}, true)
driver = appium_driver.start_driver

# Test case for the BrowserStack sample iOS app.
# If you have uploaded your app, update the test case here.
wait = Selenium::WebDriver::Wait.new(:timeout => 30)
wait.until { driver.find_element(:accessibility_id, "Text Button").displayed? }
textButton = driver.find_element(:accessibility_id, "Text Button")
Expand All @@ -40,4 +53,5 @@
puts "Test Failed"
end

# Invoke driver.quit() after the test is done to indicate that the test is completed.
driver.quit
Loading