Merge "Moving shared code to mediawiki-selenium Ruby gem"
This commit is contained in:
@@ -5,6 +5,7 @@ source 'https://rubygems.org'
|
|||||||
|
|
||||||
gem 'cucumber'
|
gem 'cucumber'
|
||||||
gem 'json'
|
gem 'json'
|
||||||
|
gem 'mediawiki-selenium'
|
||||||
gem 'net-http-persistent'
|
gem 'net-http-persistent'
|
||||||
gem 'page-object'
|
gem 'page-object'
|
||||||
gem 'rspec-expectations'
|
gem 'rspec-expectations'
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ GEM
|
|||||||
multi_json (~> 1.3)
|
multi_json (~> 1.3)
|
||||||
i18n (0.6.5)
|
i18n (0.6.5)
|
||||||
json (1.8.0)
|
json (1.8.0)
|
||||||
|
mediawiki-selenium (0.1.5)
|
||||||
multi_json (1.8.0)
|
multi_json (1.8.0)
|
||||||
multi_test (0.0.2)
|
multi_test (0.0.2)
|
||||||
net-http-persistent (2.9)
|
net-http-persistent (2.9)
|
||||||
@@ -50,6 +51,7 @@ PLATFORMS
|
|||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
cucumber
|
cucumber
|
||||||
json
|
json
|
||||||
|
mediawiki-selenium
|
||||||
net-http-persistent
|
net-http-persistent
|
||||||
page-object
|
page-object
|
||||||
rspec-expectations
|
rspec-expectations
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ Given(/^I am logged out$/) do
|
|||||||
end
|
end
|
||||||
|
|
||||||
Given(/^I am logged in$/) do
|
Given(/^I am logged in$/) do
|
||||||
visit(LoginPage).login_with(@mediawiki_username, ENV['MEDIAWIKI_PASSWORD'])
|
visit(LoginPage).login_with(ENV['MEDIAWIKI_USER'], ENV['MEDIAWIKI_PASSWORD'])
|
||||||
# Assert that login worked
|
# Assert that login worked
|
||||||
loggedin = !@browser.execute_script( "return mw.user.isAnon();" )
|
loggedin = !@browser.execute_script( "return mw.user.isAnon();" )
|
||||||
loggedin.should be_true
|
loggedin.should be_true
|
||||||
|
|||||||
@@ -1,89 +1,2 @@
|
|||||||
# before all
|
require_relative 'hooks'
|
||||||
require 'bundler/setup'
|
require 'mediawiki/selenium'
|
||||||
require 'page-object'
|
|
||||||
require 'page-object/page_factory'
|
|
||||||
require 'watir-webdriver'
|
|
||||||
require 'yaml'
|
|
||||||
|
|
||||||
World(PageObject::PageFactory)
|
|
||||||
|
|
||||||
def browser(environment, test_name, language)
|
|
||||||
if environment == :saucelabs
|
|
||||||
sauce_browser(test_name, language)
|
|
||||||
else
|
|
||||||
local_browser(language)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
def environment
|
|
||||||
if ENV['BROWSER_LABEL'] and ENV['SAUCE_ONDEMAND_USERNAME'] and ENV['SAUCE_ONDEMAND_ACCESS_KEY']
|
|
||||||
:saucelabs
|
|
||||||
else
|
|
||||||
:local
|
|
||||||
end
|
|
||||||
end
|
|
||||||
def local_browser(language)
|
|
||||||
if ENV['BROWSER_LABEL']
|
|
||||||
browser_label = ENV['BROWSER_LABEL'].to_sym
|
|
||||||
else
|
|
||||||
browser_label = :firefox
|
|
||||||
end
|
|
||||||
|
|
||||||
if language == 'default'
|
|
||||||
Watir::Browser.new browser_label
|
|
||||||
else
|
|
||||||
if browser_label == :firefox
|
|
||||||
profile = Selenium::WebDriver::Firefox::Profile.new
|
|
||||||
elsif browser_label == :chrome
|
|
||||||
profile = Selenium::WebDriver::Chrome::Profile.new
|
|
||||||
else
|
|
||||||
raise "Changing default language is currently supported only for Firefox and Chrome!"
|
|
||||||
end
|
|
||||||
profile['intl.accept_languages'] = language
|
|
||||||
Watir::Browser.new browser_label, :profile => profile
|
|
||||||
end
|
|
||||||
end
|
|
||||||
def sauce_api(json)
|
|
||||||
%x{curl -H 'Content-Type:text/json' -s -X PUT -d '#{json}' http://#{ENV['SAUCE_ONDEMAND_USERNAME']}:#{ENV['SAUCE_ONDEMAND_ACCESS_KEY']}@saucelabs.com/rest/v1/#{ENV['SAUCE_ONDEMAND_USERNAME']}/jobs/#{$session_id}}
|
|
||||||
end
|
|
||||||
def sauce_browser(test_name, language)
|
|
||||||
config = YAML.load_file('config/config.yml')
|
|
||||||
browser_label = config[ENV['BROWSER_LABEL']]
|
|
||||||
|
|
||||||
if language == 'default'
|
|
||||||
caps = Selenium::WebDriver::Remote::Capabilities.send(browser_label['name'])
|
|
||||||
elsif browser_label['name'] == 'firefox'
|
|
||||||
profile = Selenium::WebDriver::Firefox::Profile.new
|
|
||||||
profile['intl.accept_languages'] = language
|
|
||||||
caps = Selenium::WebDriver::Remote::Capabilities.firefox(:firefox_profile => profile)
|
|
||||||
elsif browser_label['name'] == 'chrome'
|
|
||||||
profile = Selenium::WebDriver::Chrome::Profile.new
|
|
||||||
profile['intl.accept_languages'] = language
|
|
||||||
caps = Selenium::WebDriver::Remote::Capabilities.chrome('chrome.profile' => profile.as_json['zip'])
|
|
||||||
end
|
|
||||||
|
|
||||||
caps.platform = browser_label['platform']
|
|
||||||
caps.version = browser_label['version']
|
|
||||||
caps[:name] = "#{test_name} #{ENV['JOB_NAME']}##{ENV['BUILD_NUMBER']}"
|
|
||||||
|
|
||||||
require 'selenium/webdriver/remote/http/persistent' # http_client
|
|
||||||
browser = Watir::Browser.new(
|
|
||||||
:remote,
|
|
||||||
http_client: Selenium::WebDriver::Remote::Http::Persistent.new,
|
|
||||||
url: "http://#{ENV['SAUCE_ONDEMAND_USERNAME']}:#{ENV['SAUCE_ONDEMAND_ACCESS_KEY']}@ondemand.saucelabs.com:80/wd/hub",
|
|
||||||
desired_capabilities: caps)
|
|
||||||
|
|
||||||
browser.wd.file_detector = lambda do |args|
|
|
||||||
# args => ['/path/to/file']
|
|
||||||
str = args.first.to_s
|
|
||||||
str if File.exist?(str)
|
|
||||||
end
|
|
||||||
|
|
||||||
browser
|
|
||||||
end
|
|
||||||
def test_name(scenario)
|
|
||||||
if scenario.respond_to? :feature
|
|
||||||
"#{scenario.feature.name}: #{scenario.name}"
|
|
||||||
elsif scenario.respond_to? :scenario_outline
|
|
||||||
"#{scenario.scenario_outline.feature.name}: #{scenario.scenario_outline.name}: #{scenario.name}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|||||||
@@ -1,25 +1,8 @@
|
|||||||
config = YAML.load_file('config/config.yml')
|
|
||||||
mediawiki_username = config['mediawiki_username']
|
|
||||||
|
|
||||||
Before do |scenario|
|
|
||||||
@config = config
|
|
||||||
@random_string = Random.new.rand.to_s
|
|
||||||
@mediawiki_username = mediawiki_username
|
|
||||||
unless @language
|
|
||||||
@browser = browser(environment, test_name(scenario), 'default')
|
|
||||||
$session_id = @browser.driver.instance_variable_get(:@bridge).session_id
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
Before('@language') do |scenario|
|
Before('@language') do |scenario|
|
||||||
@language = true
|
@language = true
|
||||||
@scenario = scenario
|
@scenario = scenario
|
||||||
end
|
end
|
||||||
|
|
||||||
Before('@login') do
|
|
||||||
puts "MEDIAWIKI_PASSWORD environment variable is not defined! Please export a value for that variable before proceeding." unless ENV['MEDIAWIKI_PASSWORD']
|
|
||||||
end
|
|
||||||
|
|
||||||
Before('@uls-in-personal-only') do |scenario|
|
Before('@uls-in-personal-only') do |scenario|
|
||||||
if uls_position() != 'personal'
|
if uls_position() != 'personal'
|
||||||
scenario.skip_invoke!
|
scenario.skip_invoke!
|
||||||
@@ -32,14 +15,6 @@ Before('@uls-in-sidebar-only') do |scenario|
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
After do |scenario|
|
|
||||||
if environment == :saucelabs
|
|
||||||
sauce_api(%Q{{"passed": #{scenario.passed?}}})
|
|
||||||
sauce_api(%Q{{"public": true}})
|
|
||||||
end
|
|
||||||
@browser.close unless ENV['KEEP_BROWSER_OPEN'] == 'true'
|
|
||||||
end
|
|
||||||
|
|
||||||
After('@reset-preferences-after') do |scenario|
|
After('@reset-preferences-after') do |scenario|
|
||||||
visit(ResetPreferencesPage)
|
visit(ResetPreferencesPage)
|
||||||
on(ResetPreferencesPage).submit_element.click
|
on(ResetPreferencesPage).submit_element.click
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
require 'cucumber/formatter/junit'
|
|
||||||
|
|
||||||
module Cucumber::Formatter
|
|
||||||
class Sauce < Junit
|
|
||||||
def format_exception(exception)
|
|
||||||
sauce_job_page = "Sauce Labs job URL: http://saucelabs.com/jobs/#{$session_id}\n"
|
|
||||||
([sauce_job_page] + ["#{exception.message} (#{exception.class})"] + exception.backtrace).join("\n")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Reference in New Issue
Block a user