Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added-CI-Variables-for-TFS #69

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
3. For each **expectation** or spec can capture console logs for **each browser instance**
4. It can generate a report analyzer - angular+bootstrap **HTML reports** with active filtering to easily find out why your tests are failing
5. HTML reports allow you to analyze your browser's **console logs** as well.
6. Supports extracting build information (the report displays a build number, a branch, etc. ) for [GitLab](https://gitlab.com) **CI/CD**, [CircleCI](https://circleci.com) and [Travis](https://travis-ci.org/).
6. Supports extracting build information (the report displays a build number, a branch, etc. ) for [GitLab](https://gitlab.com) **CI/CD**, [CircleCI](https://circleci.com), [Travis](https://travis-ci.org/) and [TFS](https://www.visualstudio.com/tfs/).
7. Supports parallel tests execution
8. Makes optional **Ascii** screenshots
9. **Multi capabilities** are supported
Expand Down Expand Up @@ -272,7 +272,7 @@ If there is a failure (based on the config) it creates also an ASCII image into

## Environmental variables

Screenshoter out-of-box obtains build information. However, some CI does not have an environmental variable for a commit message. Thus you need to obtain it manually:
Screenshoter out-of-box obtains build information. However, some CI does not have an environmental variable for a commit message or tags. Thus you need to obtain it manually:

**GitLab**
```sh
Expand All @@ -284,6 +284,12 @@ Screenshoter out-of-box obtains build information. However, some CI does not hav
export CIRCLE_MSG=$(git log -1 --pretty=%B)
```

**TFS**
(To obtain tags, please use [TFS Rest API](https://docs.microsoft.com/en-us/rest/api/vsts/build/tags/get%20build%20tags?view=vsts-rest-4.1).)
```sh
process.env["BUILD_TAG"] = TFS REST API RESPONSE;
```

If CI will support one day these variables, you won't need to enter anything in your build process.

Do you want to see exactly what is extracted, consult the code directly [obtainCIVariables](index.js#L551)
Expand Down
11 changes: 11 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,17 @@ protractorUtil.prototype.obtainCIVariables = function(env) {
url: 'https://travis-this.ci.org/' + env.TRAVIS_REPO_SLUG + '/builds/' + env.TRAVIS_BUILD_ID
}
}
if (env.TF_BUILD) {
return {
build: env.BUILD_BUILDNUMBER,
branch: env.BUILD_SOURCEBRANCHNAME,
sha: env.BUILD_SOURCEVERSION,
tag: env.BUILD_TAGS,
name: env.BUILD_DEFINITIONNAME,
commit: env.BUILD_SOURCEVERSIONMESSAGE,
url: env.SYSTEM_TEAMFOUNDATIONSERVERURI + env.SYSTEM_TEAMPROJECT + '/_build/index?buildId=' + env.BUILD_BUILDID
}
}
return {};
}
/**
Expand Down
15 changes: 15 additions & 0 deletions spec/integrational/protractor-config/ci-variables-tfs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var env = require('../environment');

exports.config = {
seleniumAddress: env.seleniumAddress,
framework: 'jasmine2',
specs: ['../protractor/ci-variables-tfs-test.js'],
plugins: [{
path: '../../../index.js',
screenshotPath: '.tmp/ci-variables-tfs',
writeReportFreq: 'asap'
}],
capabilities: {
'browserName': env.capabilities.browserName
}
};
12 changes: 12 additions & 0 deletions spec/integrational/protractor/ci-variables-tfs-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
process.env["TF_BUILD"] = true;
process.env["BUILD_BUILDNUMBER"] = '1.0.286408';
process.env["BUILD_BUILDID"] = '286408';
process.env["BUILD_SOURCEBRANCHNAME"] = 'master';
process.env["BUILD_SOURCEVERSION"] = 'sha';
process.env["BUILD_DEFINITIONNAME"] = 'a/b';
process.env["BUILD_SOURCEVERSIONMESSAGE"] = 'commit';
process.env["SYSTEM_TEAMFOUNDATIONSERVERURI"] = 'http://tfsServer:8080/tfs/Collection/';
process.env["SYSTEM_TEAMPROJECT"] = 'MyProjectName';
process.env["BUILD_TAGS"] = ["tag1, tag2"];

require("./angularjs-homepage-simple-failure-test.js");
27 changes: 25 additions & 2 deletions spec/integrational/screenshoter.int.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,6 @@ describe("Screenshoter running under protractor", function() {
done();
});
});

});

describe("pause on spec", function() {
Expand Down Expand Up @@ -1359,7 +1358,6 @@ describe("Screenshoter running under protractor", function() {
done();
});
});

});

describe("suitesConsoleErrors", function() {
Expand Down Expand Up @@ -1523,6 +1521,31 @@ describe("Screenshoter running under protractor", function() {
done();
});
});
});

describe("tfs ci variables on report", function() {
beforeAll(function() {
runProtractorWithConfig('ci-variables-tfs.js');
});

it("should generate report.js with tfs ci variables", function(done) {
fs.readFile('./tmp/ci-variables-tfs/report.js', 'utf8', function(err, data) {
if (err) {
return done.fail(err);
}
expect(data).toContain("angular.module('reporter').constant('data'");

var report = getReportAsJson(data);
expect(report.ci).toBeDefined();
expect(report.ci.build).toBe('1.0.286408');
expect(report.ci.tag).toEqual(['tag1', 'tag2']);
expect(report.ci.sha).toBe('sha');
expect(report.ci.branch).toBe('master');
expect(report.ci.name).toBe('a/b');
expect(report.ci.commit).toBe('commit');
expect(report.ci.url).toBeDefined();
});
});
});

});
26 changes: 26 additions & 0 deletions spec/unit/screenshoter.unit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,32 @@ describe("Screenshoter unit", function() {
expect(ci.commit).toEqual('commit');
expect(ci.url).toEqual('https://circleci.com/some/ulr');
});

it("should support TFS", function() {
var env = {
TF_BUILD: true,
BUILD_BUILDNUMBER: '1.0.1234',
BUILD_BUILDID: '1234',
BUILD_SOURCEBRANCHNAME: 'master',
BUILD_SOURCEVERSION: 'sha',
BUILD_TAGS: ['tag1', 'tag2'],
BUILD_DEFINITIONNAME: 'a/b',
BUILD_SOURCEVERSIONMESSAGE: 'commit',
SYSTEM_TEAMFOUNDATIONSERVERURI: 'https://www.visualstudio.com/tfs/',
SYSTEM_TEAMPROJECT: 'ProjectName'
}
var ci = screenshoter.obtainCIVariables(env);

expect(ci).toBeDefined();
expect(ci.build).toEqual('1.0.1234');
expect(ci.tag).toEqual(['tag1', 'tag2']);
expect(ci.sha).toEqual('sha');
expect(ci.branch).toEqual('master');
expect(ci.name).toEqual('a/b');
expect(ci.commit).toEqual('commit');
expect(ci.url).toEqual('https://www.visualstudio.com/tfs/ProjectName/_build/index?buildId=1234');
});


it("should support Local environment", function() {
var env = {}
Expand Down