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..573ab37f --- /dev/null +++ b/sample-code/examples/ruby/cucumber_ios_web/features/step_definitions/steps.rb @@ -0,0 +1,36 @@ +# 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) + 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) + 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 + 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') + 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..8cc1b268 --- /dev/null +++ b/sample-code/examples/ruby/cucumber_ios_web/features/support/env.rb @@ -0,0 +1,30 @@ +# 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 +Appium::Driver.new(caps) + +World do + AppiumWorld.new +end + +Before { + @driver = $driver.start_driver + @driver.get('http://saucelabs.com/test/guinea-pig') + Selenium::WebDriver::Wait.new(timeout:3).until { @driver.title.start_with?'I am a page title' } +} +After { $driver.driver_quit }