Top Level Namespace
Defined Under Namespace
Modules: MediawikiSelenium, URL
Classes: APIPage, LoginPage, RandomPage, ResetPreferencesPage
Instance Method Summary
collapse
Instance Method Details
#browser(test_name, configuration = nil) ⇒ Object
#browser_name ⇒ Object
31
32
33
34
35
36
37
|
# File 'lib/mediawiki_selenium/support/env.rb', line 31
def browser_name
if ENV["BROWSER"]
ENV["BROWSER"].to_sym
else
:firefox
end
end
|
#environment ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/mediawiki_selenium/support/env.rb', line 38
def environment
if ENV["SAUCE_ONDEMAND_USERNAME"] and ENV["SAUCE_ONDEMAND_ACCESS_KEY"] and ENV["BROWSER"] != "phantomjs" and ENV["HEADLESS"] != "true"
:saucelabs
else
:local
end
end
|
#local_browser(configuration) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/mediawiki_selenium/support/env.rb', line 45
def local_browser(configuration)
if ENV["BROWSER_TIMEOUT"] && browser_name == :firefox
timeout = ENV["BROWSER_TIMEOUT"].to_i
client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = timeout
profile = Selenium::WebDriver::Firefox::Profile.new
profile["dom.max_script_run_time"] = timeout
profile["dom.max_chrome_script_run_time"] = timeout
browser = Watir::Browser.new browser_name, :http_client => client, :profile => profile
elsif configuration && configuration[:language] && browser_name == :firefox
profile = Selenium::WebDriver::Firefox::Profile.new
profile["intl.accept_languages"] = configuration[:language]
browser = Watir::Browser.new browser_name, profile: profile
elsif configuration && configuration[:language] && browser_name == :chrome
prefs = {intl: {accept_languages: configuration[:language]}}
browser = Watir::Browser.new browser_name, prefs: prefs
elsif configuration && configuration[:language] && browser_name == :phantomjs
capabilities = Selenium::WebDriver::Remote::Capabilities.phantomjs
capabilities["phantomjs.page.customHeaders.Accept-Language"] = configuration[:language]
browser = Watir::Browser.new browser_name, desired_capabilities: capabilities
elsif configuration && configuration[:user_agent] && browser_name == :firefox
profile = Selenium::WebDriver::Firefox::Profile.new
profile["general.useragent.override"] = configuration[:user_agent]
browser = Watir::Browser.new browser_name, profile: profile
else
browser = Watir::Browser.new browser_name
end
browser.window.resize_to 1280, 1024
set_cookie(browser)
browser
end
|
#sauce_api(json) ⇒ Object
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/mediawiki_selenium/support/env.rb', line 79
def sauce_api(json)
RestClient::Request.execute(
:method => :put,
:url => "https://saucelabs.com/rest/v1/#{ENV['SAUCE_ONDEMAND_USERNAME']}/jobs/#{$session_id}",
:user => ENV["SAUCE_ONDEMAND_USERNAME"],
:password => ENV["SAUCE_ONDEMAND_ACCESS_KEY"],
:headers => {:content_type => "application/json"},
:payload => json
)
end
|
#sauce_browser(test_name, configuration) ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/mediawiki_selenium/support/env.rb', line 89
def sauce_browser(test_name, configuration)
abort "Environment variables BROWSER, PLATFORM and VERSION have to be set" if (ENV["BROWSER"] == nil) or (ENV["PLATFORM"] == nil) or (ENV["VERSION"] == nil)
client = Selenium::WebDriver::Remote::Http::Default.new
if ENV["BROWSER_TIMEOUT"] && ENV["BROWSER"] == "firefox"
timeout = ENV["BROWSER_TIMEOUT"].to_i
client.timeout = timeout
profile = Selenium::WebDriver::Firefox::Profile.new
profile["dom.max_script_run_time"] = timeout
profile["dom.max_chrome_script_run_time"] = timeout
caps = Selenium::WebDriver::Remote::Capabilities.firefox(:firefox_profile => profile)
elsif configuration && configuration[:language] && ENV["BROWSER"] == "firefox"
profile = Selenium::WebDriver::Firefox::Profile.new
profile["intl.accept_languages"] = configuration[:language]
caps = Selenium::WebDriver::Remote::Capabilities.firefox(:firefox_profile => profile)
elsif configuration && configuration[:language] && ENV["BROWSER"] == "chrome"
profile = Selenium::WebDriver::Chrome::Profile.new
profile["intl.accept_languages"] = configuration[:language]
caps = Selenium::WebDriver::Remote::Capabilities.chrome("chrome.profile" => profile.as_json["zip"])
elsif configuration && configuration[:user_agent] && ENV["BROWSER"] == "firefox"
profile = Selenium::WebDriver::Firefox::Profile.new
profile["general.useragent.override"] = configuration[:user_agent]
caps = Selenium::WebDriver::Remote::Capabilities.firefox(:firefox_profile => profile)
else
caps = Selenium::WebDriver::Remote::Capabilities.send(ENV["BROWSER"])
end
caps.platform = ENV["PLATFORM"]
caps.version = ENV["VERSION"]
caps[:name] = "#{test_name} #{ENV['JOB_NAME']}##{ENV['BUILD_NUMBER']}"
browser = Watir::Browser.new(
:remote,
http_client: client,
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|
str = args.first.to_s
str if File.exist?(str)
end
browser
end
|
#set_cookie(browser) ⇒ Object
135
136
137
|
# File 'lib/mediawiki_selenium/support/env.rb', line 135
def set_cookie(browser)
end
|
#test_name(scenario) ⇒ Object
implement this method in env.rb of the repository where it is needed
138
139
140
141
142
143
144
|
# File 'lib/mediawiki_selenium/support/env.rb', line 138
def test_name(scenario)
if scenario.respond_to? :feature
"#{scenario.feature.title}: #{scenario.title}"
elsif scenario.respond_to? :scenario_outline
"#{scenario.scenario_outline.feature.title}: #{scenario.scenario_outline.title}: #{scenario.name}"
end
end
|