diff --git a/README.md b/README.md index 6efe9b6..3022135 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -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) diff --git a/index.js b/index.js index 3fba422..13b6416 100755 --- a/index.js +++ b/index.js @@ -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 {}; } /** diff --git a/spec/integrational/protractor-config/ci-variables-tfs.js b/spec/integrational/protractor-config/ci-variables-tfs.js new file mode 100644 index 0000000..af53fbc --- /dev/null +++ b/spec/integrational/protractor-config/ci-variables-tfs.js @@ -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 + } +}; diff --git a/spec/integrational/protractor/ci-variables-tfs-test.js b/spec/integrational/protractor/ci-variables-tfs-test.js new file mode 100644 index 0000000..5718d15 --- /dev/null +++ b/spec/integrational/protractor/ci-variables-tfs-test.js @@ -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"); diff --git a/spec/integrational/screenshoter.int.spec.js b/spec/integrational/screenshoter.int.spec.js index 03f5c8c..42ff6dd 100644 --- a/spec/integrational/screenshoter.int.spec.js +++ b/spec/integrational/screenshoter.int.spec.js @@ -1330,7 +1330,6 @@ describe("Screenshoter running under protractor", function() { done(); }); }); - }); describe("pause on spec", function() { @@ -1359,7 +1358,6 @@ describe("Screenshoter running under protractor", function() { done(); }); }); - }); describe("suitesConsoleErrors", function() { @@ -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(); + }); + }); }); + }); diff --git a/spec/unit/screenshoter.unit.spec.js b/spec/unit/screenshoter.unit.spec.js index ddff29f..01a6400 100644 --- a/spec/unit/screenshoter.unit.spec.js +++ b/spec/unit/screenshoter.unit.spec.js @@ -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 = {}