Skip to content
Permalink
Browse files

[FIX JENKINS-38017 JENKINS-37323] Implement test cases with new syntax (

#30)

* [JENKINS-37323] Implement test cases with new syntax

* [JENKINS-37323] adding all known pipeline syntax as test case

* [JENKINS-37323] fix merge problem and make sure we returning always self and not coditional
  • Loading branch information...
scherler committed Sep 8, 2016
1 parent 3a3f8d8 commit 9f546a028e30a1b1c46282c9c55be028414cf57a
@@ -32,10 +32,14 @@ module.exports.commands = [{
this.waitForElementVisible('.activity-table tr#' + runName + ' svg.svgResultStatus');
this.waitForElementPresent('.activity-table tr#' + runName + ' svg circle.success');
},
waitForRunRunningVisible: function(runName) {
waitForRunRunningVisible: function(runName, callback) {
this.waitForElementVisible('.activity-table tr#' + runName);
this.waitForElementVisible('.activity-table tr#' + runName + ' svg.svgResultStatus');
this.waitForElementPresent('.activity-table tr#' + runName + ' svg path.running');
if (callback === undefined) {
this.waitForElementPresent('.activity-table tr#' + runName + ' svg path.running');
} else {
this.waitForElementPresent('.activity-table tr#' + runName + ' svg path.running', callback);
}
},
clickTab: function (browser, tab) {
var self = this;
@@ -48,8 +48,8 @@ const notEmptyHelper = function (selector, self, expectedMinimum) {
} else {
self.assert.equal(codeCollection.value.length > 0, true);
}
return self;
});
return self;
};
module.exports = {
elements: {
@@ -187,8 +187,8 @@ module.exports.commands = [{
// current, this is the reason, why no url change is triggered. The question remains
// why that is happening
// this.pause(10000)
return self;
})
return self;
},
/*
* Navigate to a certain tab by clicking on it
@@ -222,9 +222,9 @@ module.exports.commands = [{
self.validateLoading();
// did we changed the url on change?
self.assert.equal(responseInner.value.includes('start=0'), true);
return self;
})
})
return self;

},
/*
@@ -247,6 +247,7 @@ module.exports.commands = [{
self.waitForElementVisible('@progressBar');
// when we are loading the code element should not be present
this.expect.element('@code').to.not.be.present.before(1000);
return self;

},
/*
@@ -267,7 +268,6 @@ module.exports.commands = [{
self.waitForElementVisible('@logConsole');
const selector = '.logConsole';
return notEmptyHelper(selector, self, expectedMinimum);
return self;
},
/*
* validate that the log console is present
@@ -414,8 +414,8 @@ module.exports.commands = [{
// the scrollHeight has to be higher 0 to indicate that we have scrolled
browser.assert.equal(result.value > 0, true);
// to make component chain-able we will return self - part 2
return self;
});
return self;
}

}];
@@ -1,37 +1,80 @@
const async = require("async");
const stringCleaner = function (string) {
return string.replace(/\r?\n|\r/g, '');
};
// using different syntax of the same pipeline
const cases = [{
name: 'stagesClassic',
script: 'stages-with-wait.groovy',
nodeId: '5',
},{
name: 'stagesBlock',
script: 'stages-with-wait-block-syntax.groovy',
nodeId: '6',
},{
name: 'stagesPM',
script: 'stages-with-wait-pipelineModel-syntax.groovy',
nodeId: '6',
},];
/*
Create a callback wrapper - we need to make sure that we have finished before
we use the callback. If we have an error we invoke with error.
@param callback, the callback we need to call
*/
const createCallbackWrapper = function (callback) {
return function callbackWrapper(status) {
if (status && status.state) {
callback(null, status);
} else {
callback(new Error(status))
}
};
};
module.exports = {
'Create Pipeline Job "stages"': function (browser) {
const pipelinesCreate = browser.page.pipelineCreate().navigate();
pipelinesCreate.createPipeline('stages', 'stages-with-wait.groovy');
// create the different jobs
async.mapSeries(cases, function (useCase, callback) {
console.log('creating pipeline job', useCase.name, useCase.script);
// navigate to the create page
const pipelinesCreate = browser.page.pipelineCreate().navigate();
pipelinesCreate
.createPipeline(useCase.name, useCase.script, createCallbackWrapper(callback))
;
});
},

'Build Pipeline Job': function (browser) {
const pipelinePage = browser.page.jobUtils().forJob('stages');
pipelinePage.buildStarted(function() {
// Reload the job page and check that there was a build done.
pipelinePage
.waitForElementVisible('div#pipeline-box')
.forRun(1)
.waitForElementVisible('@executer');
// we need to create a browser page outside the async loop
// const pipelinesCreate = browser.page.pipelineCreate().navigate();
async.mapSeries(cases, function (useCase, callback) {
const pipelinePage = browser.page.jobUtils().forJob(useCase.name);
pipelinePage.buildStarted(function() {
// Reload the job page and check that there was a build done.
pipelinePage
.waitForElementVisible('div#pipeline-box')
.forRun(1)
.waitForElementVisible('@executer', createCallbackWrapper(callback));
});
});
},

'Check Job Blue Ocean Pipeline Activity Page has run': function (browser) {
const blueActivityPage = browser.page.bluePipelineActivity().forJob('stages', 'jenkins');
// Check the run itself
blueActivityPage.waitForRunRunningVisible('stages-1');
async.mapSeries(cases, function (useCase, callback) {
const blueActivityPage = browser.page.bluePipelineActivity().forJob(useCase.name, 'jenkins');
// Check the run itself
blueActivityPage.waitForRunRunningVisible(useCase.name + '-1', createCallbackWrapper(callback));
});
},

'Check Job Blue Ocean Pipeline run detail page - karaoke': function (browser) {
const blueRunDetailPage = browser.page.bluePipelineRunDetail().forRun('stages', 'jenkins', 1);
// this test case tests a live pipeline that is why we only running it with one case
const blueRunDetailPage = browser.page.bluePipelineRunDetail().forRun(cases[0].name, 'jenkins', 1);
blueRunDetailPage.assertBasicLayoutOkay();
// if we have the first stage finished we are sure in karaoke mode
blueRunDetailPage.waitForElementPresent('svg circle.success');
// FIXME should be taken from somewhere dynamically
// Stop karaoke and go back in graph and see the result
const nodeDetail = blueRunDetailPage.forNode('5');
const nodeDetail = blueRunDetailPage.forNode(cases[0].nodeId);
// validate that karaoke has stopped but overall process still runs
nodeDetail.waitForElementVisible('g.progress-spinner.running');
// Validate the result of the node
@@ -70,17 +113,34 @@ module.exports = {
// turn on css again
browser.useCss();
// wait for job to finish
nodeDetail.waitForJobRunEnded('stages');
nodeDetail.waitForJobRunEnded(cases[0].name);
},

'Check whether there is an EmptyStateView for stages with no steps': function (browser) {
const blueRunDetailPage = browser.page.bluePipelineRunDetail().forRun('stages', 'jenkins', 1);
blueRunDetailPage.waitForElementVisible('div.empty-state');
async.mapSeries(cases, function (useCase, callback) {
// the pipeline-model cannot have "noSteps" need to skip the test for that
if (useCase.name !== "stagesPM") {
const blueRunDetailPage = browser.page.bluePipelineRunDetail().forRun(useCase.name, 'jenkins', 1);
blueRunDetailPage.waitForElementVisible('@emptystate', createCallbackWrapper(callback));
} else {
callback(null);
}
});
},

'Check whether the artifacts tab shows artifacts': function (browser) {
const blueRunDetailPage = browser.page.bluePipelineRunDetail().forRun('stages', 'jenkins', 1);
blueRunDetailPage.clickTab('artifacts');
blueRunDetailPage.validateNotEmptyArtifacts();
async.mapSeries(cases, function (useCase, callback) {
const blueRunDetailPage = browser.page.bluePipelineRunDetail().forRun(useCase.name, 'jenkins', 1);
blueRunDetailPage.clickTab('artifacts');
blueRunDetailPage
.validateNotEmptyArtifacts(1)
.waitForElementVisible('@artifactTable', createCallbackWrapper(callback));
}, function(err, results) {
// Check whether the changes tab shows emptyState for only one case
// this test case is the finisher since we cannot finish with a async series without a closing func
const blueRunDetailPage = browser.page.bluePipelineRunDetail().forRun(cases[0].name, 'jenkins', 1);
blueRunDetailPage.clickTab('changes');
blueRunDetailPage.waitForElementVisible('@emptystate');
});
}
};
@@ -0,0 +1,21 @@
node {
stage ('Stage 1'){
sh 'sleep 3; echo `date` Stage 1;'
sh 'sleep 3; echo `date` Stage 1;'
}
stage ('Stage 2'){
parallel firstBranch: {
sh 'echo `date` Stage 2 - first;sleep 3; echo `date` Stage 2 - first;sleep 3; echo `date` Stage 2 - first;'

}, secondBranch: {
sh 'echo `date` Stage 2 - second;sleep 3; echo `date` Stage 2 - second;sleep 3; echo `date` Stage 2 - second;'
},
failFast: true
}
stage ('fin'){
sh 'echo `date` fin;sleep 3; echo `date` fin;'
sh 'echo yeah > foo.txt'
archiveArtifacts 'foo.txt'
}
stage 'NoSteps'
}
@@ -0,0 +1,16 @@
pipeline {
agent label:""
stages {
stage ('Stage 1'){
sh 'sleep 3; echo `date` Stage 1;'
sh 'sleep 3; echo `date` Stage 1;'
}

stage ('fin'){
sh 'echo `date` fin;sleep 3; echo `date` fin;'
sh 'echo yeah > foo.txt'
archiveArtifacts 'foo.txt'
}
}

}

0 comments on commit 9f546a0

Please sign in to comment.
You can’t perform that action at this time.