Skip to content

Commit

Permalink
browser tests: use lib to decode urls parts
Browse files Browse the repository at this point in the history
Use robust lib instead of string processing to extract query
parameters from urls.
See hapijs/hapi#3280 for explanation on
unintuitive query object prototype.

Bug: T187306
Change-Id: Idf80128af6859af8b7d568f59f7d825e3cdc5a91
  • Loading branch information
wiese committed Feb 19, 2018
1 parent bdea0ba commit d3bf82c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
16 changes: 10 additions & 6 deletions tests/selenium/pageobjects/search.page.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
const Page = require( '../../../../../tests/selenium/pageobjects/page' );
const url = require( 'url' );

class SearchPage extends Page {

Expand All @@ -16,7 +17,9 @@ class SearchPage extends Page {
get searchPreview() { return browser.element( '.mw-advancedSearch-searchPreview' ); }
get searchPreviewItems() { return browser.elements( '.mw-advancedSearch-searchPreview .mw-advancedSearch-searchPreview-previewPill' ); }

formWasSubmitted() { return browser.getUrl().match( /\?advancedSearchOption-original=/ ) !== null; }
formWasSubmitted() {
return Object.prototype.hasOwnProperty.call( this.getQueryFromUrl(), 'advancedSearchOption-original' );
}

advancedSearchIsCollapsed() {
return browser.element( '.mw-advancedSearch-expandablePane > .oo-ui-indicatorElement .oo-ui-indicatorElement-indicator.oo-ui-indicator-down' ).isExisting();
Expand All @@ -42,11 +45,12 @@ class SearchPage extends Page {
return browser.element( '.oo-ui-tagMultiselectWidget-group > div:nth-child(7) > span:nth-child(2)' );
}

getSearchURL() {
let search = browser.getUrl().split( '&' ).filter( function ( part ) {
return part.match( /^search=/ );
} );
return decodeURIComponent( search[ 0 ] );
getSearchQueryFromUrl() {
return this.getQueryFromUrl().search;
}

getQueryFromUrl() {
return url.parse( browser.getUrl(), true ).query;
}

getInfoPopupContent( popup ) {
Expand Down
2 changes: 1 addition & 1 deletion tests/selenium/specs/advancedsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe( 'Advanced Search', function () {
browser.keys( 'test4 test5' );
SearchPage.searchExactText.setValue( '"test1 test2"\uE007' );

assert( SearchPage.getSearchURL() === 'search=test+"test1+test2"+-test3+test4+OR+test5' );
assert.equal( SearchPage.getSearchQueryFromUrl(), 'test "test1 test2" -test3 test4 OR test5' );

} );

Expand Down
4 changes: 3 additions & 1 deletion tests/selenium/specs/searchPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ describe( 'Search in page text block functions properly', function () {
browser.keys( '40' );
SearchPage.searchImageHeight.click();
browser.keys( '40' );

SearchPage.searchButton.click();
assert( SearchPage.getSearchURL() === 'search=old+-new+big+OR+enormous+OR+giant+intitle:house+hastemplate:"Main+Page"+filemime:image/gif+filew:>40+fileh:>40' );

assert.equal( SearchPage.getSearchQueryFromUrl(), 'old -new big OR enormous OR giant intitle:house hastemplate:"Main Page" filemime:image/gif filew:>40 fileh:>40' );
} );

it( 'adds the namespace "File" and dimension fields are visible when searching for files of type image', function () {
Expand Down

0 comments on commit d3bf82c

Please sign in to comment.