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
29
30
31
32
33
34
35
|
# File 'lib/mediawiki_selenium/support/env.rb', line 29
def browser_name
if ENV["BROWSER"]
ENV["BROWSER"].to_sym
else
:firefox
end
end
|
#environment ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/mediawiki_selenium/support/env.rb', line 36
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
43
44
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
|
# File 'lib/mediawiki_selenium/support/env.rb', line 43
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
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/mediawiki_selenium/support/env.rb', line 77
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
87
88
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
|
# File 'lib/mediawiki_selenium/support/env.rb', line 87
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
133
134
135
|
# File 'lib/mediawiki_selenium/support/env.rb', line 133
def set_cookie(browser)
end
|
#test_name(scenario) ⇒ Object
implement this method in env.rb of the repository where it is needed
136
137
138
139
140
141
142
|
# File 'lib/mediawiki_selenium/support/env.rb', line 136
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
|