This repository has been archived by the owner on Jan 4, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX JENKINS-39339] contextual try Blue Ocean button (#65)
* Add "Open Blue Ocean" link to footer need it because we removed the header * Added a few custom assertions * Added some pipeline activity page empty state assertions * Added openBlueOcean custom command * Add smoke test for the "Open Blue Ocean" button * remove urlMatches - unused * Fix url encoding in urlEndsWith * Make pipeline activity basic layout testing less fragile * A test for "Open Blue Ocean" on a freestyle down in a folder * Fix urlEndsWith assertion to handle weird characters in a more human way * A test for "Open Blue Ocean" on a multibranch run down in a folder
- Loading branch information
Showing
9 changed files
with
206 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* Checks if the current url ends with the given value. | ||
* | ||
* ``` | ||
* this.demoTest = function (client) { | ||
* browser.assert.urlEndsWith('/blue/organizations/jenkins/my-pipeline/activity'); | ||
* }; | ||
* ``` | ||
* | ||
* @method urlEndsWith | ||
* @param {string} expected The expected url. | ||
* @param {string} [message] Optional log message to display in the output. If missing, one is displayed by default. | ||
* @api assertions | ||
*/ | ||
|
||
var util = require('util'); | ||
exports.assertion = function(expected, msg) { | ||
|
||
this.message = msg || util.format('Testing if the URL ends with "%s".', expected); | ||
this.expected = expected; | ||
|
||
this.pass = function(value) { | ||
if (humanize(value).endsWith(expected)) { | ||
return true; | ||
} else { | ||
console.log("urlEndsWith assert failed. The assert log (see below) shows the dehumanized URLs as seen by the browser. Here's an attempt at decoding/humanizing that URL:"); | ||
console.log("\t" + humanize(value)); | ||
return false; | ||
} | ||
}; | ||
|
||
this.value = function(result) { | ||
return result.value; | ||
}; | ||
|
||
this.command = function(callback) { | ||
this.api.url(callback); | ||
return this; | ||
}; | ||
|
||
}; | ||
|
||
function humanize(url) { | ||
var urlTokens = url.split('/'); | ||
var decodedUrlTokens = urlTokens.map(function(token) { | ||
return decodeURIComponent(token).replace(/\//g, '%2F'); | ||
}); | ||
|
||
// pop off the last token if it's empty i.e. there | ||
// was a trailing slash. | ||
if (decodedUrlTokens[decodedUrlTokens.length - 1] === '') { | ||
decodedUrlTokens.pop(); | ||
} | ||
|
||
return decodedUrlTokens.join('/'); | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/js/custom_commands/addOpenBlueOceanLinkToFooter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* @module addOpenBlueOceanLinkToFooter | ||
* @memberof custom_commands | ||
* @description Nightwatch command to add a link to Blue Ocean in the footer. Only relevant for classic Jenkins. | ||
* See http://nightwatchjs.org/guide#writing-custom-commands | ||
*/ | ||
|
||
const util = require('util'); | ||
const events = require('events'); | ||
|
||
function Cmd() { | ||
events.EventEmitter.call(this); | ||
} | ||
util.inherits(Cmd, events.EventEmitter); | ||
|
||
Cmd.prototype.command = function () { | ||
var self = this; | ||
|
||
this.api.execute(function() { | ||
(function () { | ||
function waitForJQuery() { | ||
try { | ||
// In classic Jenkins, we can try dipping into the js-modules | ||
// and get jQuery. If it's not there, then we're not in classic Jenkins | ||
// and we don't care. | ||
var $jquery = window.jenkinsCIGlobal.plugins["jquery-detached"].jquery2.exports; | ||
doTweaks($jquery); | ||
} catch(e) { | ||
setTimeout(waitForJQuery, 50); | ||
} | ||
} | ||
function doTweaks($jquery) { | ||
$jquery(function() { | ||
var contextUrlDiv = $jquery('#blueocean-context-url'); | ||
if (contextUrlDiv.length !== 0) { | ||
var footer = $jquery('#footer'); | ||
var link = $jquery('<a>Open Blue Ocean</a>'); | ||
link.attr('id', 'open-blueocean-in-context'); | ||
link.attr('href', contextUrlDiv.attr('data-context-url')); | ||
footer.append(link); | ||
} | ||
// Make the emission of the "complete" event (below) a bit | ||
// more deterministic. | ||
$jquery('body').addClass('open-blueocean-link-added'); | ||
}); | ||
} | ||
waitForJQuery(); | ||
}()); | ||
}); | ||
|
||
setTimeout(function() { | ||
self.api.waitForElementPresent('body.open-blueocean-link-added', function() { | ||
self.emit('complete'); | ||
}); | ||
}, 10); | ||
|
||
return this; | ||
}; | ||
|
||
module.exports = Cmd; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
exports.command = function (checkfor) { | ||
this.waitForElementVisible('#open-blueocean-in-context'); | ||
this.click('#open-blueocean-in-context'); | ||
if (checkfor) { | ||
this.waitForElementVisible(checkfor); | ||
} | ||
return this; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* @module classicRun | ||
* @memberof page_objects | ||
* @description Represents a Job Run page on classic Jenkins | ||
*/ | ||
|
||
exports.elements = { | ||
consoleOutput: { | ||
selector: '//a[text()="Console Output"]', | ||
locateStrategy: 'xpath', | ||
} | ||
}; | ||
exports.commands = [ | ||
{ | ||
/** | ||
* Navigate to a Job run page. | ||
* @param jobName {String} name of the job. | ||
* @param runId {String} The run Id of the run on the job. | ||
* @returns {Object} self - nightwatch page object | ||
*/ | ||
navigateToRun: function(jobName, runId) { | ||
const runUrl = this.api.launchUrl + '/job/' + jobName + '/' + (runId?runId:'1'); | ||
this.navigate(runUrl); | ||
this.waitForElementVisible('@consoleOutput'); | ||
return this; | ||
} | ||
} | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters