From 57cdd676a6cef407ed3a22ffee0ad7fe75b0a6a7 Mon Sep 17 00:00:00 2001 From: Sathish Gogineni Date: Fri, 17 Oct 2014 14:59:08 +0100 Subject: [PATCH 1/3] Added ruby project to run mobile web from cucumber --- .../cucumber_ios/features/support/appium.txt | 4 +- .../features/guniea_pig.feature} | 20 +++++----- .../features/step_definitions/steps.rb | 38 +++++++++++++++++++ .../features/support/appium.txt | 10 +++++ .../cucumber_ios_web/features/support/env.rb | 31 +++++++++++++++ 5 files changed, 91 insertions(+), 12 deletions(-) rename sample-code/examples/ruby/{cucumber_ios/features/calculator2.feature => cucumber_ios_web/features/guniea_pig.feature} (80%) create mode 100644 sample-code/examples/ruby/cucumber_ios_web/features/step_definitions/steps.rb create mode 100644 sample-code/examples/ruby/cucumber_ios_web/features/support/appium.txt create mode 100644 sample-code/examples/ruby/cucumber_ios_web/features/support/env.rb diff --git a/sample-code/examples/ruby/cucumber_ios/features/support/appium.txt b/sample-code/examples/ruby/cucumber_ios/features/support/appium.txt index 13c67200..eda32204 100644 --- a/sample-code/examples/ruby/cucumber_ios/features/support/appium.txt +++ b/sample-code/examples/ruby/cucumber_ios/features/support/appium.txt @@ -1,8 +1,8 @@ [caps] platformName = "ios" -device = "iPhone Simulator" +deviceName = "iPhone Simulator" platformVersion = "7.1" -app = "../../../apps/TestApp/build/release-iphonesimulator/TestApp.app" +app = "/Users/sathishgogineni/development/ios-test-app/build/Release-iphonesimulator/TestApp.app" [appium_lib] sauce_username = false diff --git a/sample-code/examples/ruby/cucumber_ios/features/calculator2.feature b/sample-code/examples/ruby/cucumber_ios_web/features/guniea_pig.feature similarity index 80% rename from sample-code/examples/ruby/cucumber_ios/features/calculator2.feature rename to sample-code/examples/ruby/cucumber_ios_web/features/guniea_pig.feature index a992fd13..b545f5f3 100644 --- a/sample-code/examples/ruby/cucumber_ios/features/calculator2.feature +++ b/sample-code/examples/ruby/cucumber_ios_web/features/guniea_pig.feature @@ -20,7 +20,7 @@ # # 1. Start Appium in a terminal window # 2. From another terminal window, open the cucumber example directory at -# appium/sample-code/examples/ruby/cucumber_ios/ +# appium/sample-code/examples/ruby/cucumber_web/ # 3. type 'cucumber' and hit enter # 4. If you see '1 scenario (1 passed)' and some other stuff, SUCCESS! The # test passed. If you didn't, BOOOO, that's not right. Make sure you've @@ -35,13 +35,13 @@ # https://github.com/cucumber/cucumber/wiki/Feature-Introduction -Feature: Addition - In order to revolutionize maths teaching - As an iOS developer - I want to be able to sum two numbers + Feature: + In order to explore mobile web + As an mobile web QA developer + I want to check elements in guniapig - Scenario: Add two numbers - Given I have entered 4 into field 1 of the calculator - And I have entered 7 into field 2 of the calculator - When I press button 1 - Then the result should be displayed as 11 + Scenario: Enter email and comments + Given I have entered sandbox.example@guniapig.com into Email field + And I have entered 'Test comments' into Comments field + When I click on i am a link + Then I am on other page diff --git a/sample-code/examples/ruby/cucumber_ios_web/features/step_definitions/steps.rb b/sample-code/examples/ruby/cucumber_ios_web/features/step_definitions/steps.rb new file mode 100644 index 00000000..a91ed929 --- /dev/null +++ b/sample-code/examples/ruby/cucumber_ios_web/features/step_definitions/steps.rb @@ -0,0 +1,38 @@ +# These are the 'step definitions' which Cucumber uses to implement features. +# +# Each step starts with a regular expression matching the step you write in +# your feature description. Any variables are parsed out and passed to the +# step block. +# +# The instructions in the step are then executed with those variables. +# +# The '$driver' object is the appium_lib driver, set up in the cucumber/support/env.rb +# file, which is a convenient place to put it as we're likely to use it often. +# For more on step definitions, check out the documentation at +# https://github.com/cucumber/cucumber/wiki/Step-Definitions +# +# For more on rspec assertions, check out +# https://www.relishapp.com/rspec/rspec-expectations/docs +Given(/^I have entered ([^"]*) into Email field$/) do |value| + @driver.find_element(id:'fbemail').send_keys(value) + sleep(1) + raise 'Text not entered into email' unless @driver.find_element(id:'fbemail').attribute('value').eql?value +end + +And(/^I have entered ([^"]*) into Comments field$/) do |value| + @driver.find_element(id:'comments').send_keys(value) + raise 'Text not entered into comments' unless @driver.find_element(id:'comments').attribute('value').eql?value +end + +When(/^I click on ([^"]*)$/) do |va| + element = @driver.find_element(id:va) + raise 'No link found' unless element.displayed? + element.click + @wait.until { @driver.title.start_with?'I am another page title' } +end + +Then(/^I am on other page$/) do + element = @driver.find_element(id:'i_am_an_id') + element.displayed? + raise "Doesn't open next page" unless element.text.eql?'I am another div' +end \ No newline at end of file diff --git a/sample-code/examples/ruby/cucumber_ios_web/features/support/appium.txt b/sample-code/examples/ruby/cucumber_ios_web/features/support/appium.txt new file mode 100644 index 00000000..49a1ab54 --- /dev/null +++ b/sample-code/examples/ruby/cucumber_ios_web/features/support/appium.txt @@ -0,0 +1,10 @@ +[caps] +platformName = "ios" +deviceName = "iPhone Simulator" +platformVersion = "7.1" +browserName = "Safari" +custom_url = "http://localhost:4723/wd/hub" + +[appium_lib] +sauce_username = false +sauce_access_key = false \ No newline at end of file diff --git a/sample-code/examples/ruby/cucumber_ios_web/features/support/env.rb b/sample-code/examples/ruby/cucumber_ios_web/features/support/env.rb new file mode 100644 index 00000000..e824d653 --- /dev/null +++ b/sample-code/examples/ruby/cucumber_ios_web/features/support/env.rb @@ -0,0 +1,31 @@ +# This file provides setup and common functionality across all features. It's +# included first before every test run, and the methods provided here can be +# used in any of the step definitions used in a test. This is a great place to +# put shared data like the location of your app, the capabilities you want to +# test with, and the setup of selenium. + +require 'rspec/expectations' +require 'appium_lib' +require 'cucumber/ast' +require 'selenium-webdriver' + +# Create a custom World class so we don't pollute `Object` with Appium methods +class AppiumWorld +end + +# Load the desired configuration from appium.txt, create a driver then +# Add the methods to the world +caps = Appium.load_appium_txt file: File.expand_path('./', __FILE__), verbose: true +$driver = Appium::Driver.new(caps) + +World do + AppiumWorld.new +end + +Before { + @driver = $driver.start_driver + @driver.get('http://saucelabs.com/test/guinea-pig') + @wait = Selenium::WebDriver::Wait.new(:timeout => 10) # seconds + @wait.until { @driver.title.start_with?'I am a page title' } +} +After { $driver.driver_quit } \ No newline at end of file From 1e14859aabe679606ed79d478b3471601678ef67 Mon Sep 17 00:00:00 2001 From: Sathish Gogineni Date: Fri, 17 Oct 2014 15:03:30 +0100 Subject: [PATCH 2/3] Revert change in appium file --- .../examples/ruby/cucumber_ios/features/support/appium.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sample-code/examples/ruby/cucumber_ios/features/support/appium.txt b/sample-code/examples/ruby/cucumber_ios/features/support/appium.txt index eda32204..8e5e854c 100644 --- a/sample-code/examples/ruby/cucumber_ios/features/support/appium.txt +++ b/sample-code/examples/ruby/cucumber_ios/features/support/appium.txt @@ -2,7 +2,7 @@ platformName = "ios" deviceName = "iPhone Simulator" platformVersion = "7.1" -app = "/Users/sathishgogineni/development/ios-test-app/build/Release-iphonesimulator/TestApp.app" +app = "../../../apps/TestApp/build/release-iphonesimulator/TestApp.app" [appium_lib] sauce_username = false From 59895bf3ef4a97acd4049a69433070cec482f554 Mon Sep 17 00:00:00 2001 From: Sathish Gogineni Date: Fri, 10 Apr 2015 11:17:39 +0100 Subject: [PATCH 3/3] Replaced wait function with Selenium wait. --- .../cucumber_ios_web/features/step_definitions/steps.rb | 8 +++----- .../ruby/cucumber_ios_web/features/support/env.rb | 7 +++---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/sample-code/examples/ruby/cucumber_ios_web/features/step_definitions/steps.rb b/sample-code/examples/ruby/cucumber_ios_web/features/step_definitions/steps.rb index a91ed929..573ab37f 100644 --- a/sample-code/examples/ruby/cucumber_ios_web/features/step_definitions/steps.rb +++ b/sample-code/examples/ruby/cucumber_ios_web/features/step_definitions/steps.rb @@ -15,24 +15,22 @@ # https://www.relishapp.com/rspec/rspec-expectations/docs Given(/^I have entered ([^"]*) into Email field$/) do |value| @driver.find_element(id:'fbemail').send_keys(value) - sleep(1) - raise 'Text not entered into email' unless @driver.find_element(id:'fbemail').attribute('value').eql?value + Selenium::WebDriver::Wait.new(timeout:2,message:'Text not entered into email').until { @driver.find_element(id:'fbemail').attribute('value').eql?value } end And(/^I have entered ([^"]*) into Comments field$/) do |value| @driver.find_element(id:'comments').send_keys(value) - raise 'Text not entered into comments' unless @driver.find_element(id:'comments').attribute('value').eql?value + Selenium::WebDriver::Wait.new(timeout:2,message:'Text not entered into comments').until { @driver.find_element(id:'comments').attribute('value').eql?value } end When(/^I click on ([^"]*)$/) do |va| element = @driver.find_element(id:va) raise 'No link found' unless element.displayed? element.click - @wait.until { @driver.title.start_with?'I am another page title' } + Selenium::WebDriver::Wait.new.until { @driver.title.start_with?'I am another page title' } end Then(/^I am on other page$/) do element = @driver.find_element(id:'i_am_an_id') - element.displayed? raise "Doesn't open next page" unless element.text.eql?'I am another div' end \ No newline at end of file diff --git a/sample-code/examples/ruby/cucumber_ios_web/features/support/env.rb b/sample-code/examples/ruby/cucumber_ios_web/features/support/env.rb index e824d653..8cc1b268 100644 --- a/sample-code/examples/ruby/cucumber_ios_web/features/support/env.rb +++ b/sample-code/examples/ruby/cucumber_ios_web/features/support/env.rb @@ -16,7 +16,7 @@ class AppiumWorld # Load the desired configuration from appium.txt, create a driver then # Add the methods to the world caps = Appium.load_appium_txt file: File.expand_path('./', __FILE__), verbose: true -$driver = Appium::Driver.new(caps) +Appium::Driver.new(caps) World do AppiumWorld.new @@ -25,7 +25,6 @@ class AppiumWorld Before { @driver = $driver.start_driver @driver.get('http://saucelabs.com/test/guinea-pig') - @wait = Selenium::WebDriver::Wait.new(:timeout => 10) # seconds - @wait.until { @driver.title.start_with?'I am a page title' } + Selenium::WebDriver::Wait.new(timeout:3).until { @driver.title.start_with?'I am a page title' } } -After { $driver.driver_quit } \ No newline at end of file +After { $driver.driver_quit }