From d2a2ac396cf180612522d6607fd0a86622c1c67b Mon Sep 17 00:00:00 2001 From: Tejas Shah Date: Fri, 27 Oct 2017 17:23:57 +0530 Subject: [PATCH] Add App Automate tests --- .gitignore | 1 + README.md | 11 ++- android/Gemfile | 10 +++ android/Gemfile.lock | 86 +++++++++++++++++++ android/README.md | 33 +++++++ android/Rakefile | 35 ++++++++ android/config/local.config.yml | 15 ++++ android/config/parallel.config.yml | 24 ++++++ android/config/single.config.yml | 14 +++ android/features/local.feature | 7 ++ android/features/single.feature | 8 ++ .../features/step_definitions/local_steps.rb | 13 +++ .../features/step_definitions/single_steps.rb | 15 ++++ android/features/support/env.rb | 38 ++++++++ android/features/support/hooks.rb | 7 ++ ios/Gemfile | 10 +++ ios/Gemfile.lock | 86 +++++++++++++++++++ ios/README.md | 33 +++++++ ios/Rakefile | 35 ++++++++ ios/config/local.config.yml | 15 ++++ ios/config/parallel.config.yml | 19 ++++ ios/config/single.config.yml | 14 +++ ios/features/local.feature | 7 ++ ios/features/single.feature | 8 ++ ios/features/step_definitions/local_steps.rb | 15 ++++ ios/features/step_definitions/single_steps.rb | 22 +++++ ios/features/support/env.rb | 38 ++++++++ ios/features/support/hooks.rb | 7 ++ 28 files changed, 625 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 android/Gemfile create mode 100644 android/Gemfile.lock create mode 100644 android/README.md create mode 100644 android/Rakefile create mode 100644 android/config/local.config.yml create mode 100644 android/config/parallel.config.yml create mode 100644 android/config/single.config.yml create mode 100644 android/features/local.feature create mode 100644 android/features/single.feature create mode 100644 android/features/step_definitions/local_steps.rb create mode 100644 android/features/step_definitions/single_steps.rb create mode 100644 android/features/support/env.rb create mode 100644 android/features/support/hooks.rb create mode 100644 ios/Gemfile create mode 100644 ios/Gemfile.lock create mode 100644 ios/README.md create mode 100644 ios/Rakefile create mode 100644 ios/config/local.config.yml create mode 100644 ios/config/parallel.config.yml create mode 100644 ios/config/single.config.yml create mode 100644 ios/features/local.feature create mode 100644 ios/features/single.feature create mode 100644 ios/features/step_definitions/local_steps.rb create mode 100644 ios/features/step_definitions/single_steps.rb create mode 100644 ios/features/support/env.rb create mode 100644 ios/features/support/hooks.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..90d9586 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +local.log diff --git a/README.md b/README.md index f65132f..5294bcc 100644 --- a/README.md +++ b/README.md @@ -1 +1,10 @@ -# cucumber-ruby-appium-app-browserstack +cucumber-ruby-app-browserstack +===================== +![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. + +## Resources +* [Get Started guide](https://www.browserstack.com/app-automate/appium-cucumber) +* [Android sample code repo](https://github.com/browserstack/cucumber-ruby-appium-app-browserstack/tree/master/android) +* [IOS sample code repo](https://github.com/browserstack/cucumber-ruby-appium-app-browserstack/tree/master/ios) diff --git a/android/Gemfile b/android/Gemfile new file mode 100644 index 0000000..e50ef7f --- /dev/null +++ b/android/Gemfile @@ -0,0 +1,10 @@ +source 'http://rubygems.org' + +gem 'cucumber' +gem 'selenium-cucumber' +gem 'selenium-webdriver' +gem 'rspec' +gem 'rake' +gem 'browserstack-local' +gem 'parallel_tests' +gem 'appium_lib' diff --git a/android/Gemfile.lock b/android/Gemfile.lock new file mode 100644 index 0000000..b7ed1f7 --- /dev/null +++ b/android/Gemfile.lock @@ -0,0 +1,86 @@ +GEM + remote: http://rubygems.org/ + specs: + appium_lib (9.7.1) + awesome_print (~> 1.8) + json (>= 1.8) + nokogiri (~> 1.6, >= 1.6.6) + selenium-webdriver (~> 3.4, >= 3.4.1) + tomlrb (~> 1.1) + awesome_print (1.8.0) + backports (3.8.0) + browserstack-local (1.3.0) + builder (3.2.3) + childprocess (0.8.0) + ffi (~> 1.0, >= 1.0.11) + chunky_png (1.3.8) + cucumber (3.0.1) + builder (>= 2.1.2) + cucumber-core (~> 3.0.0) + cucumber-expressions (~> 4.0.3) + cucumber-wire (~> 0.0.1) + diff-lcs (~> 1.3) + gherkin (~> 4.0) + multi_json (>= 1.7.5, < 2.0) + multi_test (>= 0.1.2) + cucumber-core (3.0.0) + backports (>= 3.8.0) + cucumber-tag_expressions (>= 1.0.1) + gherkin (>= 4.1.3) + cucumber-expressions (4.0.4) + cucumber-tag_expressions (1.0.1) + cucumber-wire (0.0.1) + diff-lcs (1.3) + ffi (1.9.18) + gherkin (4.1.3) + json (2.1.0) + mini_portile2 (2.3.0) + multi_json (1.12.2) + multi_test (0.1.2) + nokogiri (1.8.1) + mini_portile2 (~> 2.3.0) + parallel (1.12.0) + parallel_tests (2.17.0) + parallel + rake (12.0.0) + rspec (3.6.0) + rspec-core (~> 3.6.0) + rspec-expectations (~> 3.6.0) + rspec-mocks (~> 3.6.0) + rspec-core (3.6.0) + rspec-support (~> 3.6.0) + rspec-expectations (3.6.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.6.0) + rspec-mocks (3.6.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.6.0) + rspec-support (3.6.0) + rubyzip (1.2.1) + selenium-cucumber (3.1.5) + appium_lib (>= 8.0.2) + chunky_png (>= 1.3.5) + cucumber (>= 2.3.0) + rspec (>= 3.4.0) + selenium-webdriver (>= 2.53.0) + selenium-webdriver (3.6.0) + childprocess (~> 0.5) + rubyzip (~> 1.0) + tomlrb (1.2.5) + +PLATFORMS + ruby + x86_64-darwin-16 + +DEPENDENCIES + appium_lib + browserstack-local + cucumber + parallel_tests + rake + rspec + selenium-cucumber + selenium-webdriver + +BUNDLED WITH + 1.15.3 diff --git a/android/README.md b/android/README.md new file mode 100644 index 0000000..eec07ff --- /dev/null +++ b/android/README.md @@ -0,0 +1,33 @@ +## Setup +* Clone the repo +* Install dependencies `bundle install` +* Update `.config.yml` files inside the `config` directory with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings). + +## Running your tests +* Upload your Native App (.apk file) to BrowserStack servers using upload API: + + ``` + curl -u "username:accesskey" -X POST "https://api.browserstack.com/app-automate/upload" -F "file=@/path/to/app/file/Application-debug.apk" + ``` + +* If you do not have an .apk file and looking to simply try App Automate, [you can download our sample app and upload](https://www.browserstack.com/app-automate/sample-apps/android/WikipediaSample.apk) +to the BrowserStack servers using the above API. +* For running local tests, you can use our [local sample app](https://www.browserstack.com/app-automate/sample-apps/android/LocalSample.apk). +* Update the desired capability "app" with the App URL returned from the above API call +* To run a single test, run `bundle exec rake single` +* To run parallel tests, run `bundle exec rake parallel` +* To run local tests, run `bundle exec rake local` + +## Notes +* You can view your test results on the [BrowserStack Automate dashboard](https://www.browserstack.com/app-automate) +* Refer [Get Started](https://www.browserstack.com/app-automate/appium-cucumber) document to configure the capabilities +* You can export the environment variables for the Username and Access Key of your BrowserStack account. + + ``` + export BROWSERSTACK_USERNAME= && + export BROWSERSTACK_ACCESS_KEY= + ``` + +## Addtional Resources +* [Cucumber](https://cucumber.io/) +* [Getting Started with App Automate](https://www.browserstack.com/app-automate/appium-cucumber) diff --git a/android/Rakefile b/android/Rakefile new file mode 100644 index 0000000..1b34371 --- /dev/null +++ b/android/Rakefile @@ -0,0 +1,35 @@ +require 'rake' +require 'parallel' +require 'cucumber/rake/task' + +Cucumber::Rake::Task.new(:single) do |task| + ENV['CONFIG_NAME'] ||= "single" + task.cucumber_opts = ['--format=pretty', 'features/single.feature'] +end + +task :default => :single + +Cucumber::Rake::Task.new(:local) do |task| + task.cucumber_opts = ['--format=pretty', 'features/local.feature', 'CONFIG_NAME=local'] +end + +task :parallel do |t, args| + @num_parallel = 4 + + Parallel.map([*1..@num_parallel], :in_processes => @num_parallel) do |task_id| + ENV["TASK_ID"] = (task_id - 1).to_s + ENV['name'] = "parallel_test" + ENV['CONFIG_NAME'] = "parallel" + + Rake::Task["single"].invoke + Rake::Task["single"].reenable + end +end + + +task :test do |t, args| + Rake::Task["single"].invoke + Rake::Task["single"].reenable + Rake::Task["local"].invoke + Rake::Task["parallel"].invoke +end diff --git a/android/config/local.config.yml b/android/config/local.config.yml new file mode 100644 index 0000000..7e446ec --- /dev/null +++ b/android/config/local.config.yml @@ -0,0 +1,15 @@ +server: "hub.browserstack.com" +user: "BROWSERSTACK_USERNAME" +key: "BROWSERSTACK_ACCESS_KEY" + +common_caps: + "build": "cucumber-browserstack" + "browserstack.debug": true + +browser_caps: + - + "device": "Google Pixel" + "realMobile": true + "app": "bs://" + "browserstack.local": true + "name": "local_test" diff --git a/android/config/parallel.config.yml b/android/config/parallel.config.yml new file mode 100644 index 0000000..a592707 --- /dev/null +++ b/android/config/parallel.config.yml @@ -0,0 +1,24 @@ +server: "hub.browserstack.com" +user: "BROWSERSTACK_USERNAME" +key: "BROWSERSTACK_ACCESS_KEY" + +common_caps: + "build": "cucumber-browserstack" + "browserstack.debug": true + +browser_caps: + - + "device": "Google Pixel" + "realMobile": true + "app": "bs://" + "name": "parallel_test" + - + "device": "Google Nexus 5" + "realMobile": true + "app": "bs://" + "name": "parallel_test" + - + "device": "Samsung Galaxy S7" + "realMobile": true + "app": "bs://" + "name": "parallel_test" diff --git a/android/config/single.config.yml b/android/config/single.config.yml new file mode 100644 index 0000000..655f7f0 --- /dev/null +++ b/android/config/single.config.yml @@ -0,0 +1,14 @@ +server: "hub.browserstack.com" +user: "BROWSERSTACK_USERNAME" +key: "BROWSERSTACK_ACCESS_KEY" + +common_caps: + "build": "cucumber-browserstack" + "browserstack.debug": true + +browser_caps: + - + "device": "Google Pixel" + "realMobile": true + "app": "bs://" + "name": "single_test" diff --git a/android/features/local.feature b/android/features/local.feature new file mode 100644 index 0000000..fa7d0b9 --- /dev/null +++ b/android/features/local.feature @@ -0,0 +1,7 @@ +Feature: BrowserStack Local Testing + +Background: + Given I start test on the Local Sample App + +Scenario: Can check tunnel working + Then I should see "Up and running" diff --git a/android/features/single.feature b/android/features/single.feature new file mode 100644 index 0000000..1cb71a2 --- /dev/null +++ b/android/features/single.feature @@ -0,0 +1,8 @@ +Feature: Search in Wikipedia App + +Background: + Given I try to search using Wikipedia App + +Scenario: Search for a term + When I type in "BrowserStack" + Then I should see results diff --git a/android/features/step_definitions/local_steps.rb b/android/features/step_definitions/local_steps.rb new file mode 100644 index 0000000..b7cf9d8 --- /dev/null +++ b/android/features/step_definitions/local_steps.rb @@ -0,0 +1,13 @@ +When /^I start test on the Local Sample App/ do + $wait.until { $driver.find_element(:id, "com.example.android.basicnetworking:id/test_action").displayed? } + $driver.find_element(:id, "com.example.android.basicnetworking:id/test_action").click +end + +Then("I should see {string}") do |match_string| + $wait.until { $driver.find_element(:class, "android.widget.TextView").displayed? } + text_elements = $driver.find_elements(:class, "android.widget.TextView") + local_text_element = text_elements.select { |each_element| each_element.text.match(/The active connection is/) } + local_text = local_text_element.first.text + local_text.should include("The active connection is wifi.") + local_text.should include("Up and running") +end diff --git a/android/features/step_definitions/single_steps.rb b/android/features/step_definitions/single_steps.rb new file mode 100644 index 0000000..7c1f5f6 --- /dev/null +++ b/android/features/step_definitions/single_steps.rb @@ -0,0 +1,15 @@ +When /^I try to search using Wikipedia App/ do + $wait.until { $driver.find_element(:accessibility_id, "Search Wikipedia").displayed? } + $driver.find_element(:accessibility_id, "Search Wikipedia").click +end + +When("I type in {string}") do |search_keyword| + $wait.until { $driver.find_element(:id, "org.wikipedia.alpha:id/search_src_text").displayed? } + search_box = $driver.find_element(:id, "org.wikipedia.alpha:id/search_src_text") + search_box.send_key(search_keyword) + sleep 5 +end + +Then /^I should see results$/ do + $driver.find_elements(:class, "android.widget.TextView").size.should > 0 +end diff --git a/android/features/support/env.rb b/android/features/support/env.rb new file mode 100644 index 0000000..e851136 --- /dev/null +++ b/android/features/support/env.rb @@ -0,0 +1,38 @@ +require 'yaml' +require 'rspec' +require 'selenium-cucumber' +require 'browserstack/local' +require 'appium_lib' + +TASK_ID = (ENV['TASK_ID'] || 0).to_i +CONFIG_NAME = ENV['CONFIG_NAME'] || 'single' + +CONFIG = YAML.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'] + +caps = CONFIG['common_caps'].merge(CONFIG['browser_caps'][TASK_ID]) +$bs_local = nil + +if caps['browserstack.local'] && caps['browserstack.local'].to_s == 'true' + $bs_local = BrowserStack::Local.new + bs_local_args = { "key" => "#{CONFIG['key']}" } + $bs_local.start(bs_local_args) +end + +desired_caps = { + caps: caps, + appium_lib: { + server_url: "http://#{CONFIG['user']}:#{CONFIG['key']}@#{CONFIG['server']}/wd/hub" + } +} + +begin + $appium_driver = Appium::Driver.new(desired_caps, true) + $driver = $appium_driver.start_driver +rescue Exception => e + puts e.message + Process.exit(0) +end + +$wait = Selenium::WebDriver::Wait.new(:timeout => 30) diff --git a/android/features/support/hooks.rb b/android/features/support/hooks.rb new file mode 100644 index 0000000..63ddd89 --- /dev/null +++ b/android/features/support/hooks.rb @@ -0,0 +1,7 @@ +After do + $driver.quit if $driver + if $bs_local + $bs_local.stop + $bs_local = nil + end +end diff --git a/ios/Gemfile b/ios/Gemfile new file mode 100644 index 0000000..e50ef7f --- /dev/null +++ b/ios/Gemfile @@ -0,0 +1,10 @@ +source 'http://rubygems.org' + +gem 'cucumber' +gem 'selenium-cucumber' +gem 'selenium-webdriver' +gem 'rspec' +gem 'rake' +gem 'browserstack-local' +gem 'parallel_tests' +gem 'appium_lib' diff --git a/ios/Gemfile.lock b/ios/Gemfile.lock new file mode 100644 index 0000000..b7ed1f7 --- /dev/null +++ b/ios/Gemfile.lock @@ -0,0 +1,86 @@ +GEM + remote: http://rubygems.org/ + specs: + appium_lib (9.7.1) + awesome_print (~> 1.8) + json (>= 1.8) + nokogiri (~> 1.6, >= 1.6.6) + selenium-webdriver (~> 3.4, >= 3.4.1) + tomlrb (~> 1.1) + awesome_print (1.8.0) + backports (3.8.0) + browserstack-local (1.3.0) + builder (3.2.3) + childprocess (0.8.0) + ffi (~> 1.0, >= 1.0.11) + chunky_png (1.3.8) + cucumber (3.0.1) + builder (>= 2.1.2) + cucumber-core (~> 3.0.0) + cucumber-expressions (~> 4.0.3) + cucumber-wire (~> 0.0.1) + diff-lcs (~> 1.3) + gherkin (~> 4.0) + multi_json (>= 1.7.5, < 2.0) + multi_test (>= 0.1.2) + cucumber-core (3.0.0) + backports (>= 3.8.0) + cucumber-tag_expressions (>= 1.0.1) + gherkin (>= 4.1.3) + cucumber-expressions (4.0.4) + cucumber-tag_expressions (1.0.1) + cucumber-wire (0.0.1) + diff-lcs (1.3) + ffi (1.9.18) + gherkin (4.1.3) + json (2.1.0) + mini_portile2 (2.3.0) + multi_json (1.12.2) + multi_test (0.1.2) + nokogiri (1.8.1) + mini_portile2 (~> 2.3.0) + parallel (1.12.0) + parallel_tests (2.17.0) + parallel + rake (12.0.0) + rspec (3.6.0) + rspec-core (~> 3.6.0) + rspec-expectations (~> 3.6.0) + rspec-mocks (~> 3.6.0) + rspec-core (3.6.0) + rspec-support (~> 3.6.0) + rspec-expectations (3.6.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.6.0) + rspec-mocks (3.6.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.6.0) + rspec-support (3.6.0) + rubyzip (1.2.1) + selenium-cucumber (3.1.5) + appium_lib (>= 8.0.2) + chunky_png (>= 1.3.5) + cucumber (>= 2.3.0) + rspec (>= 3.4.0) + selenium-webdriver (>= 2.53.0) + selenium-webdriver (3.6.0) + childprocess (~> 0.5) + rubyzip (~> 1.0) + tomlrb (1.2.5) + +PLATFORMS + ruby + x86_64-darwin-16 + +DEPENDENCIES + appium_lib + browserstack-local + cucumber + parallel_tests + rake + rspec + selenium-cucumber + selenium-webdriver + +BUNDLED WITH + 1.15.3 diff --git a/ios/README.md b/ios/README.md new file mode 100644 index 0000000..4808da0 --- /dev/null +++ b/ios/README.md @@ -0,0 +1,33 @@ +## Setup +* Clone the repo +* Install dependencies `bundle install` +* Update `.config.yml` files inside the `config` directory with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings). + +## Running your tests +* Upload your Native App (.ipa file) to BrowserStack servers using upload API: + + ``` + curl -u "username:accesskey" -X POST "https://api.browserstack.com/app-automate/upload" -F "file=@/path/to/app/file/Application-debug.ipa" + ``` + +* If you do not have an .ipa file and looking to simply try App Automate, [you can download our sample app and upload](https://www.browserstack.com/app-automate/sample-apps/ios/WordPressSample.ipa) +to the BrowserStack servers using the above API. +* For running local tests, you can use our [local sample app](https://www.browserstack.com/app-automate/sample-apps/ios/LocalSample.ipa). +* Update the desired capability "app" with the App URL returned from the above API call +* To run a single test, run `bundle exec rake single` +* To run parallel tests, run `bundle exec rake parallel` +* To run local tests, run `bundle exec rake local` + +## Notes +* You can view your test results on the [BrowserStack Automate dashboard](https://www.browserstack.com/app-automate) +* Refer [Get Started](https://www.browserstack.com/app-automate/appium-cucumber) document to configure the capabilities +* You can export the environment variables for the Username and Access Key of your BrowserStack account. + + ``` + export BROWSERSTACK_USERNAME= && + export BROWSERSTACK_ACCESS_KEY= + ``` + +## Addtional Resources +* [Cucumber](https://cucumber.io/) +* [Getting Started with App Automate](https://www.browserstack.com/app-automate/appium-cucumber) \ No newline at end of file diff --git a/ios/Rakefile b/ios/Rakefile new file mode 100644 index 0000000..4b5fa0a --- /dev/null +++ b/ios/Rakefile @@ -0,0 +1,35 @@ +require 'rake' +require 'parallel' +require 'cucumber/rake/task' + +Cucumber::Rake::Task.new(:single) do |task| + ENV['CONFIG_NAME'] ||= "single" + task.cucumber_opts = ['--format=pretty', 'features/single.feature'] +end + +task :default => :single + +Cucumber::Rake::Task.new(:local) do |task| + task.cucumber_opts = ['--format=pretty', 'features/local.feature', 'CONFIG_NAME=local'] +end + +task :parallel do |t, args| + @num_parallel = 2 + + Parallel.map([*1..@num_parallel], :in_processes => @num_parallel) do |task_id| + ENV["TASK_ID"] = (task_id - 1).to_s + ENV['name'] = "parallel_test" + ENV['CONFIG_NAME'] = "parallel" + + Rake::Task["single"].invoke + Rake::Task["single"].reenable + end +end + + +task :test do |t, args| + Rake::Task["single"].invoke + Rake::Task["single"].reenable + Rake::Task["local"].invoke + Rake::Task["parallel"].invoke +end diff --git a/ios/config/local.config.yml b/ios/config/local.config.yml new file mode 100644 index 0000000..a732101 --- /dev/null +++ b/ios/config/local.config.yml @@ -0,0 +1,15 @@ +server: "hub.browserstack.com" +user: "BROWSERSTACK_USERNAME" +key: "BROWSERSTACK_ACCESS_KEY" + +common_caps: + "build": "cucumber-browserstack" + "browserstack.debug": true + +browser_caps: + - + "device": "iPhone 7 Plus" + "realMobile": true + "app": "bs://" + "browserstack.local": true + "name": "local_test" diff --git a/ios/config/parallel.config.yml b/ios/config/parallel.config.yml new file mode 100644 index 0000000..aa7ac1c --- /dev/null +++ b/ios/config/parallel.config.yml @@ -0,0 +1,19 @@ +server: "hub.browserstack.com" +user: "BROWSERSTACK_USERNAME" +key: "BROWSERSTACK_ACCESS_KEY" + +common_caps: + "build": "cucumber-browserstack" + "browserstack.debug": true + +browser_caps: + - + "device": "iPhone 7 Plus" + "realMobile": true + "app": "bs://" + "name": "parallel_test" + - + "device": "iPhone 7" + "realMobile": true + "app": "bs://" + "name": "parallel_test" diff --git a/ios/config/single.config.yml b/ios/config/single.config.yml new file mode 100644 index 0000000..bf3ef79 --- /dev/null +++ b/ios/config/single.config.yml @@ -0,0 +1,14 @@ +server: "hub.browserstack.com" +user: "BROWSERSTACK_USERNAME" +key: "BROWSERSTACK_ACCESS_KEY" + +common_caps: + "build": "cucumber-browserstack" + "browserstack.debug": true + +browser_caps: + - + "device": "iPhone 7 Plus" + "realMobile": true + "app": "bs://" + "name": "single_test" diff --git a/ios/features/local.feature b/ios/features/local.feature new file mode 100644 index 0000000..fa7d0b9 --- /dev/null +++ b/ios/features/local.feature @@ -0,0 +1,7 @@ +Feature: BrowserStack Local Testing + +Background: + Given I start test on the Local Sample App + +Scenario: Can check tunnel working + Then I should see "Up and running" diff --git a/ios/features/single.feature b/ios/features/single.feature new file mode 100644 index 0000000..f7552d9 --- /dev/null +++ b/ios/features/single.feature @@ -0,0 +1,8 @@ +Feature: Search in WordPress App + +Background: + Given I try to login using WordPress App + +Scenario: Login for a User + When I type in "hello@browserstack.com" in the email field + Then I should get a registration error diff --git a/ios/features/step_definitions/local_steps.rb b/ios/features/step_definitions/local_steps.rb new file mode 100644 index 0000000..7682691 --- /dev/null +++ b/ios/features/step_definitions/local_steps.rb @@ -0,0 +1,15 @@ +When /^I start test on the Local Sample App/ do + $wait.until { $driver.find_element(:id, "TestBrowserStackLocal").displayed? } + $driver.find_element(:accessibility_id, "TestBrowserStackLocal").click +end + +Then("I should see {string}") do |match_string| + sleep 5 + $wait.until do + value = $driver.find_element(:accessibility_id, "ResultBrowserStackLocal").attribute("value") + !value.nil? && value.size > 0 + end + result_text = $driver.find_element(:accessibility_id, "ResultBrowserStackLocal").text.downcase + + result_text.should include("up and running") +end diff --git a/ios/features/step_definitions/single_steps.rb b/ios/features/step_definitions/single_steps.rb new file mode 100644 index 0000000..f0bcdf2 --- /dev/null +++ b/ios/features/step_definitions/single_steps.rb @@ -0,0 +1,22 @@ +When /^I try to login using WordPress App/ do + $wait.until { $driver.find_element(:accessibility_id, "Log In").displayed? } + $driver.find_element(:accessibility_id, "Log In").click +end + +When("I type in {string} in the email field") do |search_keyword| + $wait.until { $driver.find_element(:accessibility_id, "Email address").displayed? } + search_box = $driver.find_element(:accessibility_id, "Email address") + search_box.send_keys(search_keyword) + + $wait.until { $driver.find_element(:accessibility_id, "Next").displayed? } + $driver.find_element(:accessibility_id, "Next").click +end + +Then /^I should get a registration error$/ do + sleep 5 + text_elements = $driver.find_elements(:xpath, "//XCUIElementTypeStaticText") + text_elements.size.should > 0 + + error_element = text_elements.select { |element| element.text.match(/not registered/) }.first + error_element.text.should include("not registered on WordPress.com") +end diff --git a/ios/features/support/env.rb b/ios/features/support/env.rb new file mode 100644 index 0000000..e851136 --- /dev/null +++ b/ios/features/support/env.rb @@ -0,0 +1,38 @@ +require 'yaml' +require 'rspec' +require 'selenium-cucumber' +require 'browserstack/local' +require 'appium_lib' + +TASK_ID = (ENV['TASK_ID'] || 0).to_i +CONFIG_NAME = ENV['CONFIG_NAME'] || 'single' + +CONFIG = YAML.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'] + +caps = CONFIG['common_caps'].merge(CONFIG['browser_caps'][TASK_ID]) +$bs_local = nil + +if caps['browserstack.local'] && caps['browserstack.local'].to_s == 'true' + $bs_local = BrowserStack::Local.new + bs_local_args = { "key" => "#{CONFIG['key']}" } + $bs_local.start(bs_local_args) +end + +desired_caps = { + caps: caps, + appium_lib: { + server_url: "http://#{CONFIG['user']}:#{CONFIG['key']}@#{CONFIG['server']}/wd/hub" + } +} + +begin + $appium_driver = Appium::Driver.new(desired_caps, true) + $driver = $appium_driver.start_driver +rescue Exception => e + puts e.message + Process.exit(0) +end + +$wait = Selenium::WebDriver::Wait.new(:timeout => 30) diff --git a/ios/features/support/hooks.rb b/ios/features/support/hooks.rb new file mode 100644 index 0000000..63ddd89 --- /dev/null +++ b/ios/features/support/hooks.rb @@ -0,0 +1,7 @@ +After do + $driver.quit if $driver + if $bs_local + $bs_local.stop + $bs_local = nil + end +end