From a780cb332dd723a7b9c4daaa8f61a4b14a32bf6a Mon Sep 17 00:00:00 2001 From: Chirayu Krishnappa Date: Fri, 7 Mar 2014 16:14:43 -0800 Subject: [PATCH] chore(config): allow overriding the default port --- debugging/failureConf.js | 3 +-- debugging/timeoutConf.js | 2 +- referenceConf.js | 2 +- spec/altRootConf.js | 2 +- spec/basic/lib_spec.js | 11 ++++++----- spec/basicConf.js | 2 +- spec/ciConf.js | 2 +- spec/cucumberConf.js | 2 +- spec/junitOutputConf.js | 2 +- spec/mochaConf.js | 2 +- spec/multiConf.js | 2 +- spec/onPrepareConf.js | 2 +- spec/onPrepareStringConf.js | 2 +- spec/withLoginConf.js | 7 +++++-- testapp/scripts/web-server.js | 2 +- 15 files changed, 24 insertions(+), 21 deletions(-) diff --git a/debugging/failureConf.js b/debugging/failureConf.js index 98cd855aa..a4ddf475a 100644 --- a/debugging/failureConf.js +++ b/debugging/failureConf.js @@ -1,6 +1,5 @@ // Examples of tests to show how debugging works with Protractor. Tests // should be run against the testapp. - exports.config = { seleniumAddress: 'http://localhost:4444/wd/hub', @@ -14,7 +13,7 @@ exports.config = { 'browserName': 'chrome' }, - baseUrl: 'http://localhost:8000', + baseUrl: 'http://localhost:' + (process.env.HTTP_PORT || '8000'), // ----- Options to be passed to minijasminenode. jasmineNodeOpts: { diff --git a/debugging/timeoutConf.js b/debugging/timeoutConf.js index 98d3f6d3b..40ab1b9dd 100644 --- a/debugging/timeoutConf.js +++ b/debugging/timeoutConf.js @@ -14,7 +14,7 @@ exports.config = { 'browserName': 'chrome' }, - baseUrl: 'http://localhost:8000', + baseUrl: 'http://localhost:' + (process.env.HTTP_PORT || '8000'), // ----- Options to be passed to minijasminenode. jasmineNodeOpts: { diff --git a/referenceConf.js b/referenceConf.js index bca970d1d..ff00250a6 100644 --- a/referenceConf.js +++ b/referenceConf.js @@ -86,7 +86,7 @@ exports.config = { // // A base URL for your application under test. Calls to protractor.get() // with relative paths will be prepended with this. - baseUrl: 'http://localhost:8000', + baseUrl: 'http://localhost:' + (process.env.HTTP_PORT || '8000'), // Selector for the element housing the angular app - this defaults to // body, but is necessary if ng-app is on a descendant of diff --git a/spec/altRootConf.js b/spec/altRootConf.js index f25d532e0..a75e28cc4 100644 --- a/spec/altRootConf.js +++ b/spec/altRootConf.js @@ -14,7 +14,7 @@ exports.config = { // Selector for the element housing the angular app. rootElement: 'div#nested-ng-app', - baseUrl: 'http://localhost:8000', + baseUrl: 'http://localhost:' + (process.env.HTTP_PORT || '8000'), jasmineNodeOpts: { onComplete: null, diff --git a/spec/basic/lib_spec.js b/spec/basic/lib_spec.js index 815068a96..3fc178720 100644 --- a/spec/basic/lib_spec.js +++ b/spec/basic/lib_spec.js @@ -1,4 +1,5 @@ var util = require('util'); +var port = process.env.HTTP_PORT || '8000'; describe('no protractor at all', function() { it('should still do normal tests', function() { @@ -31,15 +32,15 @@ describe('protractor library', function() { function() { browser.get('index.html'); expect(browser.getCurrentUrl()). - toEqual('http://localhost:8000/index.html#/form') + toEqual('http://localhost:'+port+'/index.html#/form') browser.driver.findElement(protractor.By.linkText('repeater')).click(); expect(browser.driver.getCurrentUrl()). - toEqual('http://localhost:8000/index.html#/repeater'); + toEqual('http://localhost:'+port+'/index.html#/repeater'); browser.navigate().back(); expect(browser.driver.getCurrentUrl()). - toEqual('http://localhost:8000/index.html#/form'); + toEqual('http://localhost:'+port+'/index.html#/form'); }); it('should export other webdriver classes onto the global protractor', @@ -95,11 +96,11 @@ describe('protractor library', function() { it('should get the absolute URL', function() { browser.get('index.html'); expect(browser.getLocationAbsUrl()). - toEqual('http://localhost:8000/index.html#/form'); + toEqual('http://localhost:'+port+'/index.html#/form'); element(by.linkText('repeater')).click(); expect(browser.getLocationAbsUrl()). - toEqual('http://localhost:8000/index.html#/repeater'); + toEqual('http://localhost:'+port+'/index.html#/repeater'); }); }) }); diff --git a/spec/basicConf.js b/spec/basicConf.js index c9e070d03..1e8f2561a 100644 --- a/spec/basicConf.js +++ b/spec/basicConf.js @@ -18,7 +18,7 @@ exports.config = { 'browserName': 'chrome' }, - baseUrl: 'http://localhost:8000', + baseUrl: 'http://localhost:' + (process.env.HTTP_PORT || '8000'), params: { login: { diff --git a/spec/ciConf.js b/spec/ciConf.js index d29ecb7ee..934ab3ef4 100644 --- a/spec/ciConf.js +++ b/spec/ciConf.js @@ -25,7 +25,7 @@ exports.config = { 'name': 'Protractor smoke tests' }], - baseUrl: 'http://localhost:8000', + baseUrl: 'http://localhost:' + (process.env.HTTP_PORT || '8000'), params: { login: { diff --git a/spec/cucumberConf.js b/spec/cucumberConf.js index c1eef983b..8bae93372 100644 --- a/spec/cucumberConf.js +++ b/spec/cucumberConf.js @@ -13,7 +13,7 @@ exports.config = { 'browserName': 'chrome' }, - baseUrl: 'http://localhost:8000', + baseUrl: 'http://localhost:' + (process.env.HTTP_PORT || '8000'), params: { login: { diff --git a/spec/junitOutputConf.js b/spec/junitOutputConf.js index f2e2ed6ac..3bfb72d07 100644 --- a/spec/junitOutputConf.js +++ b/spec/junitOutputConf.js @@ -30,5 +30,5 @@ exports.config = { } }, - baseUrl: 'http://localhost:8000', + baseUrl: 'http://localhost:' + (process.env.HTTP_PORT || '8000'), }; diff --git a/spec/mochaConf.js b/spec/mochaConf.js index 833a933c2..e19fca294 100644 --- a/spec/mochaConf.js +++ b/spec/mochaConf.js @@ -13,7 +13,7 @@ exports.config = { 'browserName': 'chrome' }, - baseUrl: 'http://localhost:8000', + baseUrl: 'http://localhost:' + (process.env.HTTP_PORT || '8000'), params: { login: { diff --git a/spec/multiConf.js b/spec/multiConf.js index f28cefd27..c7b71bab6 100644 --- a/spec/multiConf.js +++ b/spec/multiConf.js @@ -20,7 +20,7 @@ exports.config = { 'browserName': 'firefox' }], - baseUrl: 'http://localhost:8000', + baseUrl: 'http://localhost:' + (process.env.HTTP_PORT || '8000'), params: { login: { diff --git a/spec/onPrepareConf.js b/spec/onPrepareConf.js index d8e78e26c..ad621180d 100644 --- a/spec/onPrepareConf.js +++ b/spec/onPrepareConf.js @@ -11,7 +11,7 @@ exports.config = { 'browserName': 'chrome' }, - baseUrl: 'http://localhost:8000', + baseUrl: 'http://localhost:' + (process.env.HTTP_PORT || '8000'), onPrepare: function() { browser.params.password = '12345'; diff --git a/spec/onPrepareStringConf.js b/spec/onPrepareStringConf.js index 8a18ee9b6..ee1d4a2e2 100644 --- a/spec/onPrepareStringConf.js +++ b/spec/onPrepareStringConf.js @@ -12,7 +12,7 @@ exports.config = { 'browserName': 'chrome' }, - baseUrl: 'http://localhost:8000', + baseUrl: 'http://localhost:' + (process.env.HTTP_PORT || '8000'), onPrepare: 'onPrepare/startup.js' }; diff --git a/spec/withLoginConf.js b/spec/withLoginConf.js index 749ae8389..5957fc0e9 100644 --- a/spec/withLoginConf.js +++ b/spec/withLoginConf.js @@ -1,5 +1,8 @@ // This is the configuration file showing how a suite of tests might // handle log-in using the onPrepare field. +var port = + (process.env.HTTP_PORT || '8000'), + baseUrl = 'http://localhost:8000'; + exports.config = { seleniumAddress: 'http://localhost:4444/wd/hub', @@ -12,7 +15,7 @@ exports.config = { }, onPrepare: function() { - browser.driver.get('http://localhost:8000/login.html'); + browser.driver.get(baseUrl + '/login.html'); browser.driver.findElement(by.id('username')).sendKeys('Jane'); browser.driver.findElement(by.id('password')).sendKeys('1234'); @@ -28,5 +31,5 @@ exports.config = { }); }, - baseUrl: 'http://localhost:8000', + baseUrl: baseUrl, }; diff --git a/testapp/scripts/web-server.js b/testapp/scripts/web-server.js index 06b9610f5..e52a495f5 100755 --- a/testapp/scripts/web-server.js +++ b/testapp/scripts/web-server.js @@ -3,7 +3,7 @@ var express = require('express'); var util = require('util'); var testApp = express(); -var DEFAULT_PORT = 8000; +var DEFAULT_PORT = process.env.HTTP_PORT || 8000; var testAppDir = process.cwd(); var main = function(argv) {