Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Commit

Permalink
Bug/jenkins 40662 run details close problem (#93)
Browse files Browse the repository at this point in the history
* [JENKINS-40662] custom nightwatch command to watch for location changes, to avoid brittle use of pause

* [JENKINS-40662] add a test case for when user is deep-linked to run details in the URL form of :org/:pipeline/:branch/:runId and the modal doesn't close properly

* [JENKINS-40662] makes more sense to pause for location change any time the modal is closed as this will ensure downstream actions occur after the navigation is completed

* [JENKINS-40662] docs link

* [JENKINS-40662] avoid flakiness by waiting for job to finish
  • Loading branch information
cliffmeyers committed Jan 9, 2017
1 parent 039f54b commit 6d1b816
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/main/js/custom_commands/index.js
Expand Up @@ -9,4 +9,5 @@
* @see {@link module:custom_commands.waitForJobDeleted}
* @see {@link module:custom_commands.waitForJobRunEnded}
* @see {@link module:custom_commands.waitForJobRunStarted}
* @see {@link module:custom_commands.waitForLocationChange}
*/
60 changes: 60 additions & 0 deletions src/main/js/custom_commands/waitForLocationChange.js
@@ -0,0 +1,60 @@
/**
* @module waitForLocationChange
* @memberof custom_commands
*/
const util = require('util');
const events = require('events');

function Cmd() {
events.EventEmitter.call(this);
}
util.inherits(Cmd, events.EventEmitter);

var POLLING_FREQUENCY = 100;
var TIMEOUT = 5000;

/**
* @description Nightwatch command to wait for the browser's href to change.
* Polls the browser at a given frequency to wait for any change to location.href
*/
const waitForLocationChange = function () {
var self = this;
// var startTime = new Date().getTime();
var locationPollingTimeout = null;

self.api.url(function(response) {
var initialHref = response.value;

var checkForUrlChange = function() {
self.api.url(function (response) {
if (response.value !== initialHref) {
// var ellapsed = new Date().getTime() - startTime;
// console.log('url changed from: ' + initialHref + ' to: ' + response.value + 'after ' + ellapsed + ' milliseconds.');
cleanUp();
self.emit('complete');
}
else {
locationPollingTimeout = setTimeout(checkForUrlChange, POLLING_FREQUENCY);
}
});
};

var errorTimeout = setTimeout(function() {
cleanUp();
var error = new Error('timed out waiting for location change');
self.emit('error', error);
}, TIMEOUT);

var cleanUp = function() {
clearTimeout(locationPollingTimeout);
clearTimeout(errorTimeout);
};

checkForUrlChange();
});

return this;
};

Cmd.prototype.command = waitForLocationChange;
module.exports = Cmd;
17 changes: 8 additions & 9 deletions src/main/js/page_objects/blueocean/bluePipelineRunDetail.js
Expand Up @@ -148,21 +148,20 @@ module.exports.commands = [{
},
/**
* Close the modal view
* @param {String} [urlFragment] expected URL fragment to test for after close.
* @returns {Object} self - nightwatch page object
*/
closeModal: function () {
closeModal: function (urlFragment) {
const self = this;
const browser = self.api;
self.waitForElementVisible('@closeButton');
self.click('@closeButton');
browser.url(function (response) {
sanityCheck(self, response);
// FIXME JENKINS-36619 -> somehow the close in AT is not working as it should
// I debugged a bit and found out that the "previous" location is the same as
// current, this is the reason, why no url change is triggered. The question remains
// why that is happening
// this.pause(10000)
});
self.waitForLocationChange();

if (urlFragment) {
browser.assert.urlContains(urlFragment);
}

return self;
},
/**
Expand Down
39 changes: 39 additions & 0 deletions src/test/js/edgeCases/runDetailsDeepLink.js
@@ -0,0 +1,39 @@
/**
* @module runDetailsDeepLink
* @memberof edgeCases
* @description
*
* Tests: test whether navigating to Run Details without specifying a tab allows the close button to work correctly.
*
* REGRESSION covered:
*
* @see {@link https://issues.jenkins-ci.org/browse/JENKINS-40662|JENKINS-40662} Deep-linking to Run Details
* screen with no tab specified causes problem when closing modal
*/
const jobName = 'runDetailsDeepLink';
module.exports = {
/** Create Pipeline Job "runDetailsDeepLink" */
'Step 01': function (browser) {
const pipelinesCreate = browser.page.pipelineCreate().navigate();
pipelinesCreate.createPipeline(jobName, 'initialStage.groovy');
},
/** Build Pipeline Job*/
'Step 02': function (browser) {
const pipelinePage = browser.page.jobUtils().forJob(jobName);
pipelinePage.buildStarted(function () {
// Reload the job page and check that there was a build done.
pipelinePage
.waitForElementVisible('div#pipeline-box')
.forRun(1)
.waitForElementVisible('@executer');
});
},
/** Check Job Blue Ocean Pipeline Activity Page has run */
'Step 03': function (browser) {
const blueActivityPage = browser.page.bluePipelineActivity().forJob(jobName, 'jenkins');
blueActivityPage.waitForRunRunningVisible(jobName + '-1');
const blueRunDetailPage = browser.page.bluePipelineRunDetail().forRun(jobName, 'jenkins', 1);
blueRunDetailPage.waitForJobRunEnded(jobName);
blueRunDetailPage.closeModal('/activity');
},
};

0 comments on commit 6d1b816

Please sign in to comment.