I am trying to launch some tests with protractor going to SauceLabs.
I have my SauceConnect up and running. I have my protractor.config.js setup correctly I believe, but when I run the tests on my machine it with ng e2e --suite smoke, it is just running on my local machine and not going through the tunnel. Any suggestions? I have been following this "tutorial" and it has been going pretty well, but I am just not seeing anything going through the tunnel.
Here is my protractor.config.js file:
const baseUrl = '<BASEURL>';
const maxNumberOfInstances = process.env.NUMBER_OF_INSTANCES ? process.env.NUMBER_OF_INSTANCES : 1;
const reportPath = 'protractor/report';
const HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');
const screenShotReporter = new HtmlScreenshotReporter({
dest: reportPath,
filename: 'artemis-e2e-report.html'
});
const SAUCELABS_USERNAME = '<SAUCEUSERNAME';
const SAUCELABS_AUTHKEY = '<SAUCEKEY>';
const chromeArgs = process.env.IS_LOCAL ? ['--no-sandbox', '--test-type=browser', '--lang=en', '--window-size=1680,1050'] : ['--disable-gpu', '--no-sandbox', '--test-type=browser', '--lang=en', '--window-size=1680,1050'];
const browserCapabilities = [{
sauceUser: SAUCELABS_USERNAME,
sauceKey: SAUCELABS_AUTHKEY,
browserName: 'chrome',
tunnelIdentifier: '<SAUCETUNNEL>',
shardTestFiles: true,
maxInstances: maxNumberOfInstances,
platform: 'Windows 10',
version: '73.0',
screenResolution: '1280x1024',
chromeOptions: {
args: chromeArgs,
prefs: {
'credentials_enable_service': false,
'profile': {
'password_manager_enabled': false
},
download: {
prompt_for_download: false,
directory_upgrade: true,
default_directory: 'C:\\downloads\\'
},
},
},
loggingPrefs: {
browser: 'SEVERE'
},
}, ];
// Protractor config
exports.config = {
baseUrl: baseUrl,
directConnect: true,
allScriptsTimeout: 2 * 60 * 1000,
jasmineNodeOpts: {
defaultTimeoutInterval: 3 * 60 * 1000
},
getPageTimeout: 2 * 60 * 1000,
suites: {
smoke: 'protractor/smokeTests/*.scenario.ts',
},
multiCapabilities: browserCapabilities,
framework: 'jasmine2',
onPrepare: function () {
browser.waitForAngularEnabled(true);
require('ts-node').register({
project: 'protractor/tsconfig.json',
});
const jasmineReporters = require('jasmine-reporters');
const jUnitXMLReporter = new jasmineReporters.JUnitXmlReporter({
consolidateAll: false,
savePath: reportPath,
filePrefix: 'xmloutput'
});
const JasmineConsoleReporter = require('jasmine-console-reporter');
const consoleReporter = new JasmineConsoleReporter({
colors: 1,
cleanStack: 1,
verbosity: 4,
listStyle: 'indent',
activity: true,
emoji: true,
beep: true,
timeThreshold: {
ok: 10000,
warn: 15000,
ouch: 30000,
}
});
jasmine.getEnv().addReporter(jUnitXMLReporter);
jasmine.getEnv().addReporter(screenShotReporter);
jasmine.getEnv().addReporter(consoleReporter);
browser.get(browser.baseUrl);
},
beforeLaunch: function () {
return new Promise(function (resolve) {
screenShotReporter.beforeLaunch(resolve);
});
},
afterLaunch: function (exitCode) {
return new Promise(function (resolve) {
screenShotReporter.afterLaunch(resolve.bind(this, exitCode));
});
},
};
First of all you are mentioning this
it is just running on my local machine and not going through the tunnel. Any suggestions
This is not related to the tunnel, but related to:
You still have directConnect: true,, remove it from your config
You added the Sauce Labs credentials to your capabilities, but you should use them in your config file at the root level. Here's and example (it's written for TypeScript, but it should give you an idea about how to set up your config file). The tunnel identifier is correct, you only need to be sure that you are getting the correct tunnel id as #fijiaaron mentioned
Hope this helps
Where are you getting your tunnelIdentifier from?
You want to make sure:
The tunnel is running
You can access the tunnel from where you are testing
If you have a named tunnel (e.g. sc -i myTunnel) then "myTunnel" should be the tunnelIdentifier, not the tunnel id that is shown in the console outnot (i.e. not Tunnel ID: cdceac0e33db4d5fa44093e191dfdfb0)
If you have an unnamed tunnel then you should not need to specify a tunnelIdentifier for it to be used.
If you appear to be using the tunnel but cannot access your local environment, try a manual test session in Sauce Labs and select the tunnel to see if it works there.
Related
I wrote e2e test cases using a protractor. It was working fine a few days before. But now while running the test cases.
I am getting:
session not created: This version of ChromeDriver only
supports Chrome version 81 (Driver info: chromedriver=81.0.4044.69
I have already installed Google Chrome version 81. Then also I am getting the same error. I tried re-installing the node_modules but not worked.
This the configuration of my protractor.conf.json file:
const { SpecReporter } = require('jasmine-spec-reporter');
const config = require('./protractor.conf').config;
const puppeteer = require('puppeteer');
/**
* #type { import("protractor").Config }
*/
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./src/**/*.e2e-spec.ts'
],
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: [ "--headless", "--no-sandbox" ],
binary: puppeteer.executablePath()
},
},
directConnect: true,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
onPrepare() {
require('ts-node').register({
project: require('path').join(__dirname, './tsconfig.json')
});
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
}
};
Because you specify binary: puppeteer.executablePath(), this means protractor will use the browser provided by npm package puppeteer, not the browser installed by yourself.
So the issue is the version of chrome browser provided by 'puppeteer' is not 81. To make it to version 81 or change the chromedriver version to compatible with the current 'puppeteer' chrome browser. Or remove this line binary: puppeteer.executablePath() to rely on the browser which have to pre-installed on test machine manualy.
I am new to protractor and I want to be able to run my chrome browser painted or headless.
So I set up something like this
let chrome = {
browserName: 'chrome',
platform: 'MAC',
'max-duration': '1800',
};
let chromeHeadless = {
browserName: 'chrome',
chromeOptions: {
args: [ "--headless", "--disable-gpu", "--window-size=800,600" ]
}
};
browserDefault = browser.params.browserToUse
exports.config = {
params: {
'browserToUse': "get from user'
},
capabilities: browserDefault,
}
and i ran this code as
protractor config.js --params.browserToUse='chromeHeadless'
But this does not work. Protractor fails saying it does not understand "browser.params.browserInput". Whats the right way to make protractor dynamically choose chrome or chromeheadless based on the input
The global variable browser is only init when code run into onPrepare(). You used browser outside onPrepare() function, browser have not been inited, it is undefined, so you met the error.
Another point you need to get it's when the variable browser inited, a browser window has been opened, means protractor has know which capabilities to launch the browser. Therefore you can't use browser.params.xxx to specify which capabilities, you need to tell protractor the capabilities before it init the browser variable.
let capabilitiesMap = {
'chrome-headful' : {
browserName: 'chrome',
platform: 'MAC',
'max-duration': '1800',
},
'chrome-headless': {
browserName: 'chrome',
chromeOptions: {
args: [ "--headless", "--disable-gpu", "--window-size=800,600" ]
}
}
};
let browserToUse = 'chrome-headful'; // set default value
// extract the browserToUse value from cli
process.argv.slice(3).forEach(function(arg) {
var name = arg.split('=')[0];
var value = arg.split('=')[1];
var name = name.replace('--', '');
if (name === 'browserToUse') {
if (Object.prototype.hasOwnProperty.call(capabilitiesMap, value) ) {
browserToUse = value;
}
}
});
let config = {
seleniumAddress: '',
specs: [],
onPrepare: function() {}
};
config.capabilities = capabilitiesMap[browserToUse];
exports.config = config;
CLI example: protractor conf.js --browserToUse=chrome-headless
I also came across this issue and soleved it using the getMultiCapabilities() function in your conf.js
const _ = require('lodash');
let capabilities = {
chrome: {
browserName: 'chrome',
platform: 'MAC',
'max-duration': '1800',
},
chromeHeadless : {
browserName: 'chrome',
chromeOptions: {
args: [ "--headless", "--disable-gpu", "--window-size=800,600" ]
}
}
}
getMultiCapabilities() {
const browsers = this.params.browserToUse.split(',');//if you pass more than one browser e.g chrome,chromeHeadless
const cap = _(capabilities).pick(browsers).values().value(); //this uses the lodash npm module
return cap;
},
In a testing context working with just Chrome, I did the following. In capabilities:
chromeOptions: {
args: []
}
beforeLaunch: function() {
//at this point browser is not yet defined, so process command line directly
if (process.argv[process.argv.length-1].search('headless=true')>-1){
config.capabilities.chromeOptions.args.push("--headless");
config.capabilities.chromeOptions.args.push("--disable-gpu");
config.capabilities.chromeOptions.args.push("--window-size=1600,1000");
}
}
That way by the time the browser was launched, it had the right configuration. Where I have "headless=true", you might want "Chrome-headless."
And then on the command line I call it like you do with --params.headless=falseso that should I want to find it in the script itself later (after the browser has launched), it is readily available.
Note I had just one command line parameter and control of the command line, so it felt okay to assume this parameter was the last.
Protractor config file#
What is exports.config in protractor?
Do you say this: exports.config = { ... }
Is used for globals variables and configuation of your test.
For example:
exports.config = {
seleniumAddress: "http://127.0.0.1:4444/wd/hub",
baseUrl: "localhost:8080"
}]
More: https://github.com/angular/protractor/blob/master/docs/tutorial.md
exports.config in Protractor is used to specify configuration in conf.js like below:
exports.config = {
// The address of a running selenium server.
seleniumAddress: 'http://localhost:4444/wd/hub',
// define browser capabilities
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: [
'--disable-extensions',
]
}
},
// Define which tests should execute.
specs: ['test-spec.js']
// set log level
logLevel: 'verbose',
// Enables colors for log output
coloredLogs: true,
};
Default framework used is Jasmine, to run tests use below command
protractor conf.js
export.config{.....}
It is the place where we define /configure framework details, selenium details, Specs,Script timeouts, Onprepare functions, capabilities,reports and all generic stuffs.
As soon Run starts, protractor looks for this file first and tries to executes the stuffs here.
for eg) initiating selenium web-driver instances,opening Browser etc.
EG)
exports.config = {
framework: 'jasmine2', //framework Used
seleniumPort: 4444, // selenium port address
//seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['./Spec/Master.spec.js'], /*Spec -> consists of test suite/ test cases */
allScriptsTimeout: 50000,
jasmineNodeOpts: { //jasmine framework details
isVerbose: true,
showColors: true,
includeStackTrace: true,
defaultTimeoutInterval: 300000,
print: function() {}
},
capabilities: //Browser details against which test runs
{
'browserName' :'chrome',
'chromeOptions' : {
'args':['incognito','--start-maximized'], /*this line is for maximize the window and incognito view */
prefs: {
'profile:managed_default_content_settings.notifications': 1
}
}
},
//before starting the
actual TC execution, setup the things we define here
onPrepare: function (config_) {
require('./Data/waitReady.js');
//browser.manage().window().maximize();
var jasmineReporters = require('jasmine-reporters');
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
consolidateAll: false,
savePath: './Reports/JunitXMLprotractor-result/',
filePrefix: 'xmloutput'
}));
jasmine.getEnv().addReporter(
new Jasmine2HtmlReporter({
savePath: './Reports/Screenshots/',
takeScreenshots: true,
takeScreenshotsOnlyOnFailures: true,
consolidateAll: true,
showPassed: true,
// filePrefix: sessionId + 'AutomationReport',
filePrefix: 'AutomationReport',
cleanDestination: true,
})
);
global.isAngularSite = function(flag){
browser.driver.ignoreSynchronization = !flag;
};
i have tried to use Jasmine HTML reporter along with the Protractor HTML reporter.
My Config.js code look like this
var HtmlReporter = require('protractor-html-screenshot-reporter');
jasmine.getEnv().addReporter(new HtmlReporter({
baseDirectory: '/protractor-result',
docTitle: 'Protractor Demo Reporter',
docName: 'protractor-demo-tests-report.html'
}));
var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
jasmine.getEnv().addReporter(new Jasmine2HtmlReporter({
savePath: '../Report/HTML/',
showSummary: true,
showQuickLinks: true,
showConfiguration: true,
screenshotsFolder: 'images',
takeScreenshots: true,
takeScreenshotsOnlyOnFailures: true,
fixedScreenshotName: true,
ignoreSkippedSpecs: true,
consolidate: true,
consolidateAll: true,
preserveDirectory: true,
reportTitle: 'Protractor-Execution-Report-' + timeStamp
}));
i could able to see HTML reports generated by Jasmine but still unable to see the HTML reports generated by Protractor.Please correct me if i am trying something unreal.
Any help would be appreciated.
protractor-html-screenshot-reporter is not compatible with jasmine 2 and latest version of protractor uses jasmine 2 by default, instead switch to
protractor-jasmine2-html-reporter
You need to put those lines inside your onPrepare section of the protractor.config.js file:
var HtmlReporter = require('protractor-html-screenshot-reporter');
var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
exports.config = {
//other stuff
onPrepare: function() {
// Add a screenshot reporter and store screenshots to `/tmp/screnshots`:
jasmine.getEnv().addReporter(new HtmlReporter({
baseDirectory: '/tmp/screenshots'
//...
}));
jasmine.getEnv().addReporter(new Jasmine2HtmlReporter({
savePath: '../Report/HTML/'
//...
}));
}
}
I know this is pretty old, but I ran into an issue trying to get jasmine-reporters and protractor-jasmine2-html-reporter to work and didn't like the idea that I had to downgrade in order for them to work. I found out that protractor-jasmine2-html-reporter wasn't resolving the savePath correctly and was actually putting the reports folder output in protractor-jasmine2-html-reporter directory instead of the root directory of where I ran gulp. In order to make this work correctly I ended up using process.env.INIT_CWD to get the initial Current Working Directory which should be the directory where you ran gulp. Hope this helps someone.
var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
var jasmine2HtmlReporter = new Jasmine2HtmlReporter({
savePath: process.env.INIT_CWD + '/report/e2e/',
screenshotsFolder: 'images',
takeScreenshots: true,
takeScreenshotsOnlyOnFailures: true,
fileName: 'index.html'
});
onPrepare: function () {
jasmine.getEnv().addReporter(jasmine2HtmlReporter);
}
I use protractor-jasmine2-screenshot-reporter and protractor-jasmine2-html-reporter to handle that, here is my configuration file protractor.conf.js, hope it can help you.
var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');
var jasmine2HtmlReporter = new Jasmine2HtmlReporter({
savePath: 'report/e2e/protractor-jasmine2-html-reporter/',
filePrefix: 'index',
screenshotsFolder: 'screenshots'
});
var htmlScreenshotReporter = new HtmlScreenshotReporter({
dest: 'report/e2e/protractor-jasmine2-screenshot-reporter/',
filename: 'index.html'
});
exports.config = {
allScriptsTimeout: 11000,
specs: [
'*.e2e.js'
],
capabilities: {
'browserName': 'chrome'
},
baseUrl: 'http://localhost:8080/app/',
framework: 'jasmine',
jasmineNodeOpts: {
defaultTimeoutInterval: 30000,
showColors: true
},
// Setup the report before any tests start
beforeLaunch: function() {
return new Promise(function(resolve){
htmlScreenshotReporter.beforeLaunch(resolve);
});
},
// Assign the test reporter to each running instance
onPrepare: function () {
jasmine.getEnv().addReporter(jasmine2HtmlReporter);
jasmine.getEnv().addReporter(htmlScreenshotReporter);
},
// Close the report after all tests finish
afterLaunch: function(exitCode) {
return new Promise(function(resolve){
htmlScreenshotReporter.afterLaunch(resolve.bind(this, exitCode));
});
}
};
For details you see here
I've the following config.js file:
var testName = 'Testing';
var HtmlReporter = require('protractor-html-screenshot-reporter');
var reporter = new HtmlReporter({
baseDirectory: './protractor-result', // a location to store screen shots.
docTitle: 'Report Test Summary',
docName: 'protractor-tests-report.html'
});
exports.config = {
seleniumAddress: 'http://hub.browserstack.com/wd/hub',
multiCapabilities: [
{
name: testName,
browserName: 'Chrome',
browser_version: '39.0',
os: 'OS X',
os_version: 'Yosemite',
resolution: '1920x1080',
'browserstack.user': browserstackUser,
'browserstack.key': browserstackKey,
'browserstack.debug': 'true',
'browserstack.selenium_version': '2.45.0'
}
,
{
name: testName,
browserName: 'IE',
browser_version: '11.0',
os: 'Windows',
os_version: '8.1',
resolution: '2048x1536',
'browserstack.user': browserstackUser,
'browserstack.key': browserstackKey,
'browserstack.debug': 'true',
'browserstack.selenium_version': '2.45.0',
'browserstack.ie.driver': '2.44',
//ignoreProtectedModeSettings: true
}
],
// Spec patterns are relative to the current working directly when
// protractor is called.
suites: {
waitlist: './././specs/waitlist_page_spec.js',
press: './././specs/press_page_spec.js',
news: './././specs/news_page_spec.js',
landing: './././specs/landing_page_spec.js'
},
// Maximum number of total browser sessions to run. Tests are queued in
// sequence if number of browser sessions is limited by this parameter.
// Use a number less than 1 to denote unlimited. Default is unlimited.
maxSessions: 2,
// protractor will save the test output in json format at this path.
// The path is relative to the location of this config.
resultJsonOutputFile: null,
framework: 'jasmine2',
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 100000,
realtimeFailure: true,
showTiming: true,
includeStackTrace: true,
isVerbose: true,
onComplete: null
},
onPrepare: function () {
jasmine.getEnv().addReporter(reporter);
browser.driver.manage().window().maximize();
global.dvr = browser.driver; //variable to call selenium directly
global.isAngularSite = function (flag) {
browser.ignoreSynchronization = !flag; //This setup is to configure when testing non-angular pages
};
//browser.manage().timeouts().pageLoadTimeout(90000);
browser.manage().timeouts().implicitlyWait(100000);
}
};
And I would like to find a way to ask on my test that if the capability.browserName is IE do a certain/especial action, so, I would like to do some sort of getConfig(), is that possible? does anyone had implemented something similar?
Thanks all for your time!
The getCapabilities in browser returns a promise with these values:
browser.getCapabilities().then(function (capabilities) {
browser = capabilities.caps_.browserName;
platform = capabilities.caps_.platform;
}).then(function displayEnv() {
console.log('Browser:', browser, 'on platform', platform);
});