Skip to content

Commit df112c4

Browse files
authored
Merge pull request #7 from kn-neeraj/qsg-firsttest-changes
Updated first test script according to QSG spec and added Bundler to manage dependencies
2 parents bb5f35d + dba1f18 commit df112c4

File tree

9 files changed

+252
-91
lines changed

9 files changed

+252
-91
lines changed

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source 'http://rubygems.org'
2+
3+
gem 'appium_lib', ">=10.5.0"
4+
gem 'browserstack-local', ">=1.3.0"

Gemfile.lock

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
GEM
2+
remote: http://rubygems.org/
3+
specs:
4+
appium_lib (10.6.0)
5+
appium_lib_core (~> 3.3)
6+
nokogiri (~> 1.8, >= 1.8.1)
7+
tomlrb (~> 1.1)
8+
appium_lib_core (3.10.1)
9+
faye-websocket (~> 0.10.0)
10+
selenium-webdriver (~> 3.14, >= 3.14.1)
11+
browserstack-local (1.3.0)
12+
childprocess (3.0.0)
13+
eventmachine (1.2.7)
14+
faye-websocket (0.10.9)
15+
eventmachine (>= 0.12.0)
16+
websocket-driver (>= 0.5.1)
17+
mini_portile2 (2.4.0)
18+
nokogiri (1.10.10)
19+
mini_portile2 (~> 2.4.0)
20+
rubyzip (2.3.0)
21+
selenium-webdriver (3.142.7)
22+
childprocess (>= 0.5, < 4.0)
23+
rubyzip (>= 1.2.2)
24+
tomlrb (1.3.0)
25+
websocket-driver (0.7.3)
26+
websocket-extensions (>= 0.1.0)
27+
websocket-extensions (0.1.5)
28+
29+
PLATFORMS
30+
ruby
31+
32+
DEPENDENCIES
33+
appium_lib (>= 10.5.0)
34+
browserstack-local (>= 1.3.0)
35+
36+
BUNDLED WITH
37+
2.1.4

README.md

Lines changed: 110 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,115 @@
11
# ruby-appium-app-browserstack
2-
App Automate Ruby Samples
3-
---------------------
42

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

7-
For frameworks integration with BrowserStack, refer to their individual repositories -
5+
## Setup
6+
7+
### Requirements
8+
9+
1. Ruby 2.2+
10+
11+
- If not installed, install Ruby from [here](https://www.ruby-lang.org/en/documentation/installation/)
12+
13+
2. Dependency Manager `bundler`
14+
15+
- If not installed, run command `gem install bundler`
16+
17+
### Install the dependencies
18+
19+
To install the dependencies, run the following command in the project's base directory :
20+
21+
```ruby
22+
bundle install
23+
```
24+
25+
**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 -
26+
27+
```ruby
28+
gem install ffi
29+
gem uninstall -aIx eventmachine
30+
gem install eventmachine --platform=ruby
31+
```
32+
33+
## Getting Started
34+
35+
Getting Started with Appium tests in Ruby on BrowserStack couldn't be easier!
36+
37+
### Run your first test :
38+
39+
**1. Upload your Android or iOS App**
40+
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 :
41+
42+
```
43+
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
44+
-X POST "https://api-cloud.browserstack.com/app-automate/upload" \
45+
-F "file=@/path/to/apk/file"
46+
```
47+
48+
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.
49+
50+
**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).
51+
52+
**2. Configure and run your first test**
53+
54+
Open `browserstack_sample.rb` file in `android` or `ios` directory :
55+
56+
- Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials. Get your BrowserStack access credentials from [here](https://www.browserstack.com/accounts/settings)
57+
58+
- Replace `bs://<app-id>` wkth the URL obtained from app upload step
59+
60+
- Set the device and OS version
61+
62+
- If you have uploaded your own app update the test case
63+
64+
- Run `ruby browserstack_sample.rb`
65+
66+
- 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)
67+
68+
---
69+
70+
### Use Local testing for apps that access resources hosted in development or testing environments :
71+
72+
**1. Upload your Android or iOS App**
73+
74+
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 :
75+
76+
```
77+
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
78+
-X POST "https://api-cloud.browserstack.com/app-automate/upload" \
79+
-F "file=@/path/to/apk/file"
80+
```
81+
82+
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.
83+
84+
**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).
85+
86+
87+
**2. Configure and run your local test**
88+
89+
Open `browserstack_sample_local.rb` file in `android` or `ios` directory :
90+
91+
- Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials. Get your BrowserStack access credentials from [here](https://www.browserstack.com/accounts/settings)
92+
93+
- Replace `bs://<app-id>` wkth the URL obtained from app upload step
94+
95+
- Set the device and OS version
96+
97+
- 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.
98+
99+
- If you have uploaded your own app update the test case
100+
101+
- Run `ruby browserstack_sample_local.rb`
102+
103+
- 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)
104+
105+
## Integration with other frameworks
106+
107+
For other Ruby frameworks samples, refer to following repositories :
8108

9109
- [Cucumber](https://github.com/browserstack/cucumber-ruby-appium-app-browserstack)
110+
111+
Note: For other test frameworks supported by App-Automate refer our [Developer documentation](https://www.browserstack.com/docs/)
112+
113+
## Getting Help
114+
115+
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).

android/README.md

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,37 @@
22
require 'appium_lib'
33
require 'selenium-webdriver'
44

5-
username = 'BROWSERSTACK_USERNAME'
6-
access_key = 'BROWSERSTACK_ACCESS_KEY'
7-
85
caps = {}
9-
caps['build'] = 'Ruby Appium Sample'
6+
# Set your access credentials
7+
caps['browserstack.user'] = 'YOUR_USERNAME'
8+
caps['browserstack.key'] = 'YOUR_ACCESS_KEY'
9+
10+
# Set URL of the application under test
11+
caps['app'] = 'bs://<app-id>'
12+
13+
# Specify device and os_version for testing
14+
caps['device'] = 'Google Pixel 3'
15+
caps['os_version'] = '9.0'
16+
17+
# Set other BrowserStack capabilities
18+
caps['project'] = 'First Ruby project'
19+
caps['build'] = 'Ruby Android'
1020
caps['name'] = 'single_test'
11-
caps['device'] = 'Google Pixel'
21+
22+
#Set the platform name
1223
caps['platformName'] = 'android'
13-
caps['browserstack.debug'] = true
14-
caps['app'] = 'bs://<hashed app-id>'
1524

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

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

53+
# Invoke driver.quit() after the test is done to indicate that the test is completed.
4054
driver.quit
Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,47 @@
33
require 'selenium-webdriver'
44
require 'browserstack/local'
55

6-
username = 'BROWSERSTACK_USERNAME'
7-
access_key = 'BROWSERSTACK_ACCESS_KEY'
6+
username = 'YOUR_USERNAME'
7+
access_key = 'YOUR_ACCESS_KEY'
88

99
caps = {}
10-
caps['build'] = 'Ruby Appium Sample'
10+
# Set your access credentials
11+
caps['browserstack.user'] = username
12+
caps['browserstack.key'] = access_key
13+
14+
# Set URL of the application under test
15+
caps['app'] = 'bs://<app-id>'
16+
17+
# Specify device and os_version for testing
18+
caps['device'] = 'Google Pixel 3'
19+
caps['os_version'] = '9.0'
20+
21+
# Set browserstack.local capability as true
22+
caps['browserstack.local'] = true
23+
24+
# Set other BrowserStack capabilities
25+
caps['project'] = 'First Ruby project'
26+
caps['build'] = 'Ruby Android Local'
1127
caps['name'] = 'local_test'
12-
caps['device'] = 'Google Pixel'
1328
caps['platformName'] = 'android'
14-
caps['browserstack.local'] = true
1529
caps['browserstack.debug'] = true
16-
caps['app'] = 'bs://<hashed app-id>'
1730

31+
# Start browserstack local
1832
bs_local = BrowserStack::Local.new
1933
bs_local_args = { "key" => access_key }
2034
bs_local.start(bs_local_args)
2135

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

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

61+
# Invoke driver.quit() after the test is done to indicate that the test is completed.
4362
driver.quit
63+
# Stop browserstack local
4464
bs_local.stop

ios/README.md

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,37 @@
22
require 'appium_lib'
33
require 'selenium-webdriver'
44

5-
username = 'BROWSERSTACK_USERNAME'
6-
access_key = 'BROWSERSTACK_ACCESS_KEY'
7-
85
caps = {}
9-
caps['build'] = 'Ruby Appium Sample'
6+
# Set your access credentials
7+
caps['browserstack.user'] = 'YOUR_USERNAME'
8+
caps['browserstack.key'] = 'YOUR_ACCESS_KEY'
9+
10+
# Set URL of the application under test
11+
caps['app'] = 'bs://<app-id>'
12+
13+
# Specify device and os_version for testing
14+
caps['device'] = "iPhone 11 Pro"
15+
caps['os_version'] = "13"
16+
17+
# Set other BrowserStack capabilities
18+
caps['project'] = 'First Ruby project'
19+
caps['build'] = 'Ruby iOS'
1020
caps['name'] = 'single_test'
11-
caps['device'] = 'iPhone 7 Plus'
21+
22+
#Set the platform name
1223
caps['platformName'] = 'iOS'
13-
caps['browserstack.debug'] = true
14-
caps['app'] = 'bs://<hashed app-id>'
1524

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

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

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

0 commit comments

Comments
 (0)