Refactoring tests to make them more robust
Fixed typo in feature description. Merged two background steps since the last one did not have any actions that could be done manually. Removed assertions from a "given" (login) step. We already extensively test logging in. If this extension needs login tests, they should go to a separate feature file. Moved methods from steps file to page file, following page object pattern. Change-Id: Ic5250970362718f5ed887c9ac8fd56948724b210
This commit is contained in:
committed by
Niklas Laxström
parent
afc5774ee2
commit
f45d5bfcd5
@@ -6,13 +6,12 @@ Feature: Font selection
|
|||||||
I want to change or disable the fonts for interface and content.
|
I want to change or disable the fonts for interface and content.
|
||||||
|
|
||||||
In addition the user is provided live preview feature: changes are applied
|
In addition the user is provided live preview feature: changes are applied
|
||||||
immediately when selection is made. Changes can either be applied or discared
|
immediately when selection is made. Changes can either be applied or discarded
|
||||||
for easy testing.
|
for easy testing.
|
||||||
|
|
||||||
Background:
|
Background:
|
||||||
Given I am logged in
|
Given I am logged in
|
||||||
And I set "German" as the interface language
|
And I set "German" as the interface language
|
||||||
And I inspect current fonts
|
|
||||||
|
|
||||||
Scenario: Font selector appears
|
Scenario: Font selector appears
|
||||||
When I open "Fonts" panel of language settings
|
When I open "Fonts" panel of language settings
|
||||||
|
|||||||
@@ -7,55 +7,25 @@ end
|
|||||||
|
|
||||||
Given(/^I am logged in$/) do
|
Given(/^I am logged in$/) do
|
||||||
visit(LoginPage).login_with(ENV['MEDIAWIKI_USER'], ENV['MEDIAWIKI_PASSWORD'])
|
visit(LoginPage).login_with(ENV['MEDIAWIKI_USER'], ENV['MEDIAWIKI_PASSWORD'])
|
||||||
# Assert that login worked
|
|
||||||
loggedin = !@browser.execute_script( "return mw.user.isAnon();" )
|
|
||||||
loggedin.should be_true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Given(/^I set "(.*?)" as the interface language$/) do |language|
|
Given(/^I set "(.*?)" as the interface language$/) do |language|
|
||||||
code = language_to_code(language)
|
code = on(PanelPage).language_to_code(language)
|
||||||
visit(PanelPage, :using_params => {:extra => "setlang=#{code}"})
|
visit(PanelPage, :using_params => {:extra => "setlang=#{code}"})
|
||||||
|
@original_content_font = on(PanelPage).get_content_font
|
||||||
|
@original_interface_font = on(PanelPage).get_interface_font
|
||||||
end
|
end
|
||||||
|
|
||||||
Given(/^I temporarily use "(.*?)" as the interface language$/) do |language|
|
Given(/^I temporarily use "(.*?)" as the interface language$/) do |language|
|
||||||
code = language_to_code(language)
|
code = on(PanelPage).language_to_code(language)
|
||||||
visit(PanelPage, :using_params => {:extra => "uselang=#{code}"})
|
visit(PanelPage, :using_params => {:extra => "uselang=#{code}"})
|
||||||
end
|
end
|
||||||
|
|
||||||
Then(/^my interface language is "(.*?)"$/) do |language|
|
Then(/^my interface language is "(.*?)"$/) do |language|
|
||||||
code = language_to_code(language)
|
code = on(PanelPage).language_to_code(language)
|
||||||
on(PanelPage).interface_element.attribute('lang').should == code
|
on(PanelPage).interface_element.attribute('lang').should == code
|
||||||
end
|
end
|
||||||
|
|
||||||
def language_to_code(language)
|
|
||||||
case language
|
|
||||||
when 'German'
|
|
||||||
'de'
|
|
||||||
when 'English'
|
|
||||||
'en'
|
|
||||||
when 'Finnish'
|
|
||||||
'fi'
|
|
||||||
when 'Hebrew'
|
|
||||||
'he'
|
|
||||||
when 'Hindi'
|
|
||||||
'hi'
|
|
||||||
else
|
|
||||||
pending
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def get_font(selector)
|
|
||||||
@browser.execute_script( "return $( '#{selector}' ).css( 'font-family' );" )
|
|
||||||
end
|
|
||||||
|
|
||||||
def get_content_font()
|
|
||||||
get_font('#mw-content-text')
|
|
||||||
end
|
|
||||||
|
|
||||||
def get_interface_font()
|
|
||||||
get_font('body')
|
|
||||||
end
|
|
||||||
|
|
||||||
def uls_position()
|
def uls_position()
|
||||||
if !defined?($uls_position)
|
if !defined?($uls_position)
|
||||||
visit(PanelPage)
|
visit(PanelPage)
|
||||||
|
|||||||
@@ -2,11 +2,6 @@ Then(/^I see "(.*?)" as the name of the content language$/) do |text|
|
|||||||
@browser.span(:text => "#{text}").should be_visible
|
@browser.span(:text => "#{text}").should be_visible
|
||||||
end
|
end
|
||||||
|
|
||||||
Given(/^I inspect current fonts$/) do
|
|
||||||
@original_content_font = get_content_font()
|
|
||||||
@original_interface_font = get_interface_font()
|
|
||||||
end
|
|
||||||
|
|
||||||
When(/^I open "(.*?)" panel of language settings$/) do |panel|
|
When(/^I open "(.*?)" panel of language settings$/) do |panel|
|
||||||
on(PanelPage) do |page|
|
on(PanelPage) do |page|
|
||||||
# Open the ULS panel if it's not open already
|
# Open the ULS panel if it's not open already
|
||||||
@@ -58,9 +53,9 @@ end
|
|||||||
Then(/^the active (.*?) font must be the same as font prior to the preview$/) do |type|
|
Then(/^the active (.*?) font must be the same as font prior to the preview$/) do |type|
|
||||||
case type
|
case type
|
||||||
when "content"
|
when "content"
|
||||||
get_content_font().should === @original_content_font
|
on(PanelPage).get_content_font.should === @original_content_font
|
||||||
when "interface"
|
when "interface"
|
||||||
get_interface_font().should === @original_interface_font
|
on(PanelPage).get_interface_font.should === @original_interface_font
|
||||||
else
|
else
|
||||||
pending
|
pending
|
||||||
end
|
end
|
||||||
@@ -86,9 +81,9 @@ end
|
|||||||
Then(/^the (.*) font must be changed to the "(.*?)" font$/) do |type, font|
|
Then(/^the (.*) font must be changed to the "(.*?)" font$/) do |type, font|
|
||||||
case type
|
case type
|
||||||
when "content"
|
when "content"
|
||||||
get_content_font().should match("^#{font}")
|
on(PanelPage).get_content_font.should match("^#{font}")
|
||||||
when "interface"
|
when "interface"
|
||||||
get_interface_font().should match("^#{font}")
|
on(PanelPage).get_interface_font.should match("^#{font}")
|
||||||
else
|
else
|
||||||
pending
|
pending
|
||||||
end
|
end
|
||||||
@@ -111,7 +106,7 @@ Then(/^a font selector for content language appears$/) do
|
|||||||
end
|
end
|
||||||
|
|
||||||
When(/^I use the panel to change my interface language to "(.*?)"$/) do |language|
|
When(/^I use the panel to change my interface language to "(.*?)"$/) do |language|
|
||||||
code = language_to_code(language)
|
code = on(PanelPage).language_to_code(language)
|
||||||
on(RandomPage).language_filter = code
|
on(RandomPage).language_filter = code
|
||||||
# Because one browser wants :enter and other :return -- sigh
|
# Because one browser wants :enter and other :return -- sigh
|
||||||
on(RandomPage).language_filter_element.send_keys [:enter, "\n"]
|
on(RandomPage).language_filter_element.send_keys [:enter, "\n"]
|
||||||
|
|||||||
@@ -34,6 +34,6 @@ And(/^I click on the link to select Hindi$/) do
|
|||||||
end
|
end
|
||||||
|
|
||||||
Then(/^I should see the text in the language panel in (.+?)$/) do |language|
|
Then(/^I should see the text in the language panel in (.+?)$/) do |language|
|
||||||
code = language_to_code(language)
|
code = on(PanelPage).language_to_code(language)
|
||||||
on(PanelPage).uls_display_settings_element.attribute('lang').should == code
|
on(PanelPage).uls_display_settings_element.attribute('lang').should == code
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -38,4 +38,30 @@ class PanelPage
|
|||||||
|
|
||||||
# Is there way to access the html element?
|
# Is there way to access the html element?
|
||||||
div(:interface, id: 'footer')
|
div(:interface, id: 'footer')
|
||||||
|
|
||||||
|
def get_content_font
|
||||||
|
get_font('#mw-content-text')
|
||||||
|
end
|
||||||
|
def get_font(selector)
|
||||||
|
@browser.execute_script( "return $( '#{selector}' ).css( 'font-family' );" )
|
||||||
|
end
|
||||||
|
def get_interface_font
|
||||||
|
get_font('body')
|
||||||
|
end
|
||||||
|
def language_to_code(language)
|
||||||
|
case language
|
||||||
|
when 'German'
|
||||||
|
'de'
|
||||||
|
when 'English'
|
||||||
|
'en'
|
||||||
|
when 'Finnish'
|
||||||
|
'fi'
|
||||||
|
when 'Hebrew'
|
||||||
|
'he'
|
||||||
|
when 'Hindi'
|
||||||
|
'hi'
|
||||||
|
else
|
||||||
|
pending
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user