Skip to content

Commit c917482

Browse files
author
Tejas Shah
committed
Add App Automate tests
1 parent 8273639 commit c917482

File tree

8 files changed

+240
-0
lines changed

8 files changed

+240
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
local.log

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
11
# ruby-appium-app-browserstack
2+
App Automate Ruby Samples
3+
---------------------
4+
5+
This repository contains code for Automated Native App tests. Please feel free to clone the repo and use the example code.
6+
7+
For frameworks integration with BrowserStack, refer to their individual repositories -
8+
9+
- [Cucumber](https://github.com/browserstack/cucumber-ruby-appium-app-browserstack)

android/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## Android
2+
3+
## Prerequisites
4+
- Install the appium_lib gem<br>
5+
`gem install 'appium_lib'`
6+
- Install the local bindings gem (if you need to run local tests)<br>
7+
`gem install 'browserstack/local'`
8+
9+
## Running your tests
10+
- Do remember to switch the USERNAME and ACCESS_KEY with your own browserstack credentials.
11+
- Upload your Native App (.apk file) to BrowserStack servers using upload API:
12+
13+
```
14+
curl -u "username:accesskey" -X POST "https://api.browserstack.com/app-automate/upload" -F "file=@/path/to/app/file/Application-debug.apk"
15+
```
16+
17+
- If you do not have an .apk file and looking to simply try App Automate, you can download our [sample app](https://www.browserstack.com/app-automate/sample-apps/android/WikipediaSample.apk)
18+
and upload to the BrowserStack servers using the above API.
19+
- For running local tests, you can use our [local sample app](https://www.browserstack.com/app-automate/sample-apps/android/LocalSample.apk).
20+
- Update the desired capability "app" with the App URL returned from the above API call
21+
22+
## Notes
23+
* You can view your test results on the [BrowserStack App Automate dashboard](https://www.browserstack.com/app-automate)
24+
* Refer [Get Started](https://www.browserstack.com/app-automate/appium-ruby) document to configure the capabilities
25+
26+
For frameworks integration with BrowserStack, refer to their individual repositories -
27+
28+
- [Cucumber](https://github.com/browserstack/cucumber-ruby-appium-app-browserstack)

android/local_test.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
require 'rubygems'
2+
require 'appium_lib'
3+
require 'selenium-webdriver'
4+
require 'browserstack/local'
5+
6+
username = 'BROWSERSTACK_USERNAME'
7+
access_key = 'BROWSERSTACK_ACCESS_KEY'
8+
9+
caps = {}
10+
caps['build'] = 'Ruby Appium Sample'
11+
caps['name'] = 'local_test'
12+
caps['device'] = 'Google Pixel'
13+
caps['realMobile'] = true
14+
caps['browserstack.local'] = true
15+
caps['browserstack.debug'] = true
16+
caps['app'] = 'bs://<hashed app-id>'
17+
18+
bs_local = BrowserStack::Local.new
19+
bs_local_args = { "key" => access_key }
20+
bs_local.start(bs_local_args)
21+
22+
appium_driver = Appium::Driver.new({
23+
'caps' => caps,
24+
'appium_lib' => {
25+
:server_url => "http://#{username}:#{access_key}@hub.browserstack.com/wd/hub"
26+
}}, true)
27+
driver = appium_driver.start_driver
28+
29+
wait = Selenium::WebDriver::Wait.new(:timeout => 30)
30+
wait.until { driver.find_element(:id, "com.example.android.basicnetworking:id/test_action").displayed? }
31+
element = driver.find_element(:id, "com.example.android.basicnetworking:id/test_action")
32+
element.click
33+
34+
wait.until { driver.find_element(:class, "android.widget.TextView").displayed? }
35+
text_elements = driver.find_elements(:class, "android.widget.TextView")
36+
37+
if text_elements.map(&:text).any?{|x| x.match('Up and running')}
38+
puts "Up and Running - Test Passed"
39+
else
40+
puts "Local Testing setup not working - Test Failed"
41+
end
42+
43+
driver.quit
44+
bs_local.stop

android/single_test.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
require 'rubygems'
2+
require 'appium_lib'
3+
require 'selenium-webdriver'
4+
5+
username = 'BROWSERSTACK_USERNAME'
6+
access_key = 'BROWSERSTACK_ACCESS_KEY'
7+
8+
caps = {}
9+
caps['build'] = 'Ruby Appium Sample'
10+
caps['name'] = 'single_test'
11+
caps['device'] = 'Google Pixel'
12+
caps['realMobile'] = true
13+
caps['browserstack.debug'] = true
14+
caps['app'] = 'bs://<hashed app-id>'
15+
16+
appium_driver = Appium::Driver.new({
17+
'caps' => caps,
18+
'appium_lib' => {
19+
:server_url => "http://#{username}:#{access_key}@hub.browserstack.com/wd/hub"
20+
}}, true)
21+
driver = appium_driver.start_driver
22+
23+
wait = Selenium::WebDriver::Wait.new(:timeout => 30)
24+
wait.until { driver.find_element(:accessibility_id, "Search Wikipedia").displayed? }
25+
element = driver.find_element(:accessibility_id, "Search Wikipedia")
26+
element.click
27+
28+
wait.until { driver.find_element(:id, "org.wikipedia.alpha:id/search_src_text").displayed? }
29+
search_box = driver.find_element(:id, "org.wikipedia.alpha:id/search_src_text")
30+
search_box.send_keys("BrowserStack")
31+
sleep 5
32+
33+
results = driver.find_elements(:class, "android.widget.TextView")
34+
if results.count > 0
35+
puts "Found results - Test Passed"
36+
else
37+
puts "No results found - Test Failed"
38+
end
39+
40+
driver.quit

ios/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## iOS
2+
3+
## Prerequisites
4+
- Install the appium_lib gem<br>
5+
`gem install 'appium_lib'`
6+
- Install the local bindings gem (if you need to run local tests)<br>
7+
`gem install 'browserstack/local'`
8+
9+
## Running your tests
10+
- Do remember to switch the USERNAME and ACCESS_KEY with your own browserstack credentials.
11+
- Upload your Native App (.ipa file) to BrowserStack servers using upload API:
12+
13+
```
14+
curl -u "username:accesskey" -X POST "https://api.browserstack.com/app-automate/upload" -F "file=@/path/to/app/file/Application-debug.ipa"
15+
```
16+
17+
- If you do not have an .ipa file and looking to simply try App Automate, you can download our [sample app](https://www.browserstack.com/app-automate/sample-apps/ios/WordPressSample.ipa)
18+
and upload to the BrowserStack servers using the above API.
19+
- For running local tests, you can use our [local sample app](https://www.browserstack.com/app-automate/sample-apps/ios/LocalSample.ipa).
20+
- Update the desired capability "app" with the App URL returned from the above API call
21+
22+
## Notes
23+
* You can view your test results on the [BrowserStack App Automate dashboard](https://www.browserstack.com/app-automate)
24+
* Refer [Get Started](https://www.browserstack.com/app-automate/appium-ruby) document to configure the capabilities
25+
26+
For frameworks integration with BrowserStack, refer to their individual repositories -
27+
28+
- [Cucumber](https://github.com/browserstack/cucumber-ruby-appium-app-browserstack)

ios/local_test.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
require 'rubygems'
2+
require 'appium_lib'
3+
require 'selenium-webdriver'
4+
require 'browserstack/local'
5+
6+
username = 'BROWSERSTACK_USERNAME'
7+
access_key = 'BROWSERSTACK_ACCESS_KEY'
8+
9+
caps = {}
10+
caps['build'] = 'Ruby Appium Sample'
11+
caps['name'] = 'local_test'
12+
caps['device'] = 'iPhone 7 Plus'
13+
caps['realMobile'] = true
14+
caps['browserstack.local'] = true
15+
caps['browserstack.debug'] = true
16+
caps['app'] = 'bs://<hashed app-id>'
17+
18+
bs_local = BrowserStack::Local.new
19+
bs_local_args = { "key" => access_key }
20+
bs_local.start(bs_local_args)
21+
22+
appium_driver = Appium::Driver.new({
23+
'caps' => caps,
24+
'appium_lib' => {
25+
:server_url => "http://#{username}:#{access_key}@hub.browserstack.com/wd/hub"
26+
}}, true)
27+
driver = appium_driver.start_driver
28+
29+
wait = Selenium::WebDriver::Wait.new(:timeout => 30)
30+
wait.until { driver.find_element(:accessibility_id, "TestBrowserStackLocal").displayed? }
31+
test_button = driver.find_element(:accessibility_id, "TestBrowserStackLocal")
32+
test_button.click
33+
34+
wait.until do
35+
value = driver.find_element(:accessibility_id, "ResultBrowserStackLocal").attribute("value")
36+
!value.nil? && value.size > 0
37+
end
38+
39+
result_element = driver.find_element(:accessibility_id, "ResultBrowserStackLocal")
40+
41+
if result_element.text.match("Up and running")
42+
puts "Test Passed"
43+
else
44+
puts "Test Failed"
45+
end
46+
47+
driver.quit
48+
bs_local.stop

ios/single_test.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
require 'rubygems'
2+
require 'appium_lib'
3+
require 'selenium-webdriver'
4+
5+
username = 'BROWSERSTACK_USERNAME'
6+
access_key = 'BROWSERSTACK_ACCESS_KEY'
7+
8+
caps = {}
9+
caps['build'] = 'Ruby Appium Sample'
10+
caps['name'] = 'single_test'
11+
caps['device'] = 'iPhone 7 Plus'
12+
caps['realMobile'] = true
13+
caps['browserstack.debug'] = true
14+
caps['app'] = 'bs://<hashed app-id>'
15+
16+
appium_driver = Appium::Driver.new({
17+
'caps' => caps,
18+
'appium_lib' => {
19+
:server_url => "http://#{username}:#{access_key}@hub.browserstack.com/wd/hub"
20+
}}, true)
21+
driver = appium_driver.start_driver
22+
23+
wait = Selenium::WebDriver::Wait.new(:timeout => 30)
24+
wait.until { driver.find_element(:accessibility_id, "Log In").displayed? }
25+
login_button = driver.find_element(:accessibility_id, "Log In")
26+
login_button.click
27+
28+
wait.until { driver.find_element(:accessibility_id, "Email address").displayed? }
29+
email_input = driver.find_element(:accessibility_id, "Email address")
30+
email_input.send_keys("hello@browserstack.com")
31+
32+
wait.until { driver.find_element(:accessibility_id, "Next").displayed? }
33+
driver.find_element(:accessibility_id, "Next").click
34+
sleep 5
35+
36+
results = driver.find_elements(:xpath, "//XCUIElementTypeStaticText")
37+
if results.map(&:text).any?{|x| x.match('not registered on WordPress.com')}
38+
puts "Test Passed"
39+
else
40+
puts "Test Failed"
41+
end
42+
43+
driver.quit

0 commit comments

Comments
 (0)