mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/MultimediaViewer
synced 2024-11-27 01:20:02 +00:00
c5a245309d
Fixed up feature indentation and clauses and moved global methods into the page-object classes. Added @custom-browser tag to avoid starting multiple browser sessions and updated mediawiki_selenium dependency for fix to custom browser instantiation with SauceLabs. Change-Id: I9741afb8d13ee8729f72210eb7617d9446311a8e
52 lines
1.7 KiB
Ruby
52 lines
1.7 KiB
Ruby
require "json"
|
|
|
|
class CommonsPage
|
|
include PageObject
|
|
|
|
page_url URL.url("File:Sunrise_over_fishing_boats_in_Kerala.jpg")
|
|
|
|
img(:commons_image, src: /Kerala\.jpg$/)
|
|
div(:mmv_image_loaded_cucumber, class: "mw-mmv-image-loaded-cucumber")
|
|
|
|
def wait_for_image_load(selector)
|
|
browser.execute_script <<-end_script
|
|
function wait_for_image() {
|
|
var $img = $( #{selector.to_json} );
|
|
if ( $img.length
|
|
&& $img.attr( 'src' ).match(/Kerala/)
|
|
&& !$img.attr( 'src' ).match(/\\/220px-/) // Blurry placeholder
|
|
&& $img.prop( 'complete' ) ) {
|
|
$( 'body' ).append( '<div class=\"mw-mmv-image-loaded-cucumber\"/>' );
|
|
} else {
|
|
setTimeout( wait_for_image, 10 );
|
|
}
|
|
}
|
|
wait_for_image();
|
|
end_script
|
|
|
|
wait_until { mmv_image_loaded_cucumber_element.exists? }
|
|
end
|
|
|
|
def log_performance(stats)
|
|
stats = stats.reject { |name, value| value.nil? || value.to_s.empty? }
|
|
stats[:duration] = stats[:duration].floor
|
|
|
|
browser.execute_script <<-end_script
|
|
mediaWiki.eventLog.declareSchema( 'MultimediaViewerVersusPageFilePerformance',
|
|
{ schema:
|
|
{ title: 'MultimediaViewerVersusPageFilePerformance',
|
|
properties: {
|
|
type: { type: 'string', required: true, enum: [ 'mmv', 'file-page' ] },
|
|
duration: { type: 'integer', required: true },
|
|
cache: { type: 'string', required: false, enum: [ 'cold', 'warm' ] },
|
|
windowSize: { type: 'string', required: false, enum: [ 'average', 'large'] }
|
|
}
|
|
},
|
|
revision: 7907636
|
|
});
|
|
|
|
mw.eventLog.logEvent( 'MultimediaViewerVersusPageFilePerformance', #{stats.to_json} );
|
|
end_script
|
|
end
|
|
end
|