WebDriverError: Could not start Browser / Emulator error - protractor

Oflate , I have been observing below error when ran my protractor tests on browserstack.
"UnhandledPromiseRejectionWarning: WebDriverError: Could not start Browser / Emulator"
Here is my protractor config file.
let browserstack = _.defaults({
user: process.env.BROWSERSTACK_USERNAME,
key: process.env.BROWSERSTACK_ACCESS_KEY
}, {
user: '**',
key: '**'
});
let timeoutMultiplier = 2;
exports.makeDefaultCapabilities = function(that) {
return {
browserName: 'chrome',
chromeOptions: {
prefs: {
credentials_enable_service: false,
},
loggingPrefs: {
driver: 'WARNING',
server: 'WARNING',
browser: 'INFO'
},
'browserstack.user': browserstack.user,
'browserstack.key': browserstack.key,
'browserstack.debug': true,
build: that.params.BUILD_NUMBER || '(unknown)',
maxInstances: 2,
name: that.baseUrl,
}
};
exports.config = {
suites: {
e2e: [
'*/*.spec.js'
]
},
SELENIUM_PROMISE_MANAGER: false,
baseUrl: undefined,
framework: 'jasmine',
jasmineNodeOpts: {
defaultTimeoutInterval: 60 * 1000 * timeoutMultiplier,
realtimeFailure: true
},
maxSessions: 1,
params: {
BUILD_NUMBER: undefined,
CI: undefined,
TIMEOUT_MULTIPLIER: timeoutMultiplier
},
seleniumAddress: 'https://hub-cloud.browserstack.com/wd/hub',
useAllAngular2AppRoots: true,
getMultiCapabilities: function() {
return new Promise(function(resolve) {
let capabilities = [];
capabilities.push({
os: 'OS X',
os_version: 'High Sierra'
});
resolve(capabilities);
});
},
onPrepare: function() {
browser.manage().window().maximize();
jasmine.getEnv().addReporter(failFast.init());
let reporter = new SpecReporter();
jasmine.getEnv().addReporter(reporter);
}
};
Test that is failing :
calling function :
async clickButton() {
await browser.waitForAngularEnabled(false);
await waitForEl(this.Button);
await browser.sleep(10000);
await this.Button.click();
await browser.sleep(10000);
await this.stopButton.click();
await waitForElAbsence(this.Bar);
await browser.waitForAngularEnabled(true);
}
used above calling function in below spec:
it('should check if button is clicable', async function() {
let po = new check({
url
});
await po.go();
await po.clickButton();
});
Has any one experienced it before ? Also the error is seen only browserstack and not on my local computer. Also the test i pasted is not the only one failing . Tests are failing randomly with this error.
I have protractor v5.3.2

Related

Server side error while executing the script in appium

I was trying to execute the appium script in an virtual emulator.But while executing i am getting this below error.In emulator the app is launched but it doesn't perform any action gets closed.
Error:-
[16:52:46] E/launcher - An unknown server-side error occurred while processing the command. Original error: No Chromedriver found that can automate Chrome '77.0.3865'. See https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/web/chromedriver.md for more details. You could also try to enable automated chromedrivers download server feature
[16:52:46] E/launcher - WebDriverError: An unknown server-side error occurred while processing the command. Original error: No Chromedriver found that can automate Chrome '77.0.3865'. See https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/web/chromedriver.md for more details. You could also try to enable automated chromedrivers download server feature
[16:52:46] E/launcher - Process exited with error code 199
Conf File:-
const { SpecReporter } = require('jasmine-spec-reporter');
exports.config = {
allScriptsTimeout: 300000,
seleniumAddress: 'http://localhost:4723/wd/hub',
specs: [
'./e2e/**/login.mobile.ts',
],
useAllAngular2AppRoots: true,
//chromeDriver: './node_modules/chromedriver/lib/chromedriver/chromedriver.exe',
capabilities: {
platformName: 'Android',
platformVersion: '9',
deviceName: 'emulator-5554',
browserName: '',
appiumVersion:'1.16.0',
autoWebview: true,
autoWebviewTimeout: 10000,
autoacceptalerts: true,
autoGrantPermissions: true,
clearSystemFiles: true,
app: './platforms/android/build/outputs/apk/android-debug.apk
},
//baseUrl: 'http://10.0.2.2:8000',
plugins: [
{
path: require.resolve('protractor-console'),
logLevels: ['severe'],
package: 'jasmine2-protractor-utils',
disableHTMLReport: false,
disableScreenshot: false,
screenshotPath: './screenshots',
screenshotOnExpectFailure: true,
screenshotOnSpecFailure: true,
clearFoldersBeforeTest: true
}
],
// directConnect: true, //enable for desktop
//baseUrl: 'http://localhost:4723/wd/hub',
framework: 'jasmine2',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 300000,
print: function() {}
},
beforeLaunch: function() {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
},
onPrepare() {
var jasmineReporters = require('jasmine-reporters');
jasmine.getEnv().addReporter(
new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
savePath: './report/mobile',
filePrefix: 'xmlresults'
})
);
var wd = require('wd'),
protractor = require('protractor'),
wdBridge = require('wd-bridge')(protractor, wd);
wdBridge.initFromProtractor(exports.config);
},
onComplete: function() {
var browserName, browserVersion;
var capsPromise = browser.getCapabilities();
capsPromise.then(function(caps) {
browserName = caps.get('browserName');
browserVersion = caps.get('version');
var HTMLReport = require('protractor-html-reporter');
testConfig = {
reportTitle: 'CVM Test Execution Report',
outputPath: './report/mobile', //relative path
screenshotPath: './screenshots',
testBrowser: 'Mobile',
browserVersion: browserVersion,
modifiedSuiteName: false,
screenshotsOnlyOnFailure: true
};
new HTMLReport().from('./report/mobile/xmlresults.xml', testConfig);
});
}
};

Wait and Sleep does not work on protractor

I'm having trouble testing a screen with automated tests, I'm filling in all input fields and then pushing the submit button, but wait / sleep doesn't seem to be working this causes the button to be pressed before the input is filled.
Why is my sleep / wait not working?
describe('Wizard - Organizacional data - Test Plan - 150454', function () {
const functionsPage = new functionObjectPage();
it('148454 - Incluir informações do administrador e Escritório.', function() {
browser.wait(until.presenceOf(element(by.id('openWizard'))), 30000, '');
browser.executeScript("document.querySelector('#openWizard').click()");
browser.executeScript("document.querySelector('#usuarioPrincipal').value = 'User master'");
browser.executeScript("document.querySelector('#emailUsuarioPrincipal').value = 'master#master.com'");
browser.executeScript("document.querySelector('#officeName').value = 'Office Name'");
browser.executeScript("document.querySelector('#cnpj').value = '57375882000197'");
browser.sleep(5500);
browser.executeScript("document.querySelector('#btnNextStep').click()");
});
});
I don't know if browser.ignoreSynchronization = true; influences how sleep / wait works, or if any other config can influence it.
This is my protactor config:
var SpecReporter = require('jasmine-spec-reporter').SpecReporter;
var env = process.env.env || 'local';
var config = require('./e2e/src/helper/config')[env];
var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
exports.config = {
directConnect: true,
capabilities: {
browserName: 'chrome'
},
SELENIUM_PROMISE_MANAGER: false,
framework: 'jasmine',
specs: [
'./e2e/src/*_spec.js',
],
suites: {
pages: './e2e/src/*_spec_suite.js',
},
baseUrl: config.baseUrl,
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 2000000,
print: function () {}
},
onPrepare: function () {
require('jasmine2-custom-message');
var jasmineReporters = require('jasmine-reporters');
var junitReporter = new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
savePath: 'testresults',
filePrefix: 'reportXMLoutput'
});
jasmine.getEnv().addReporter(
new Jasmine2HtmlReporter({
savePath: 'testresults/screenshots'
}));
jasmine.getEnv().addReporter(junitReporter);
jasmine.getEnv().addReporter(new SpecReporter({
suite: {
displayNumber: true
},
spec: {
displayStacktrace: true,
displayErrorMessages: true,
displaySuccessful: true,
displayFailed: true,
displayPending: true,
displayDuration: true
}
}));
browser.ignoreSynchronization = true;
browser.driver.manage().timeouts().implicitlyWait(15000);
browser.driver.manage().window().maximize();
}
};
You have SELENIUM_PROMISE_MANAGER: false in your config which means you need to use async/await to perform step synchronously
describe('Wizard - Organizacional data - Test Plan - 150454', () => {
const functionsPage = new functionObjectPage();
it('148454 - Incluir informações do administrador e Escritório.', async () => {
await browser.wait(until.presenceOf(element(by.id('openWizard'))), 30000, '');
await browser.executeScript("document.querySelector('#openWizard').click()");
etc..
etc..

Having test spec name as test name in browserstack

I want to set the test spec name as the test name in browserstack. Below is my browserstack stack config file. I am using protractor.
exports.makeDefaultCapabilities = function(that) {
return {
browserName: 'chrome',
chromeOptions: {
prefs: {
credentials_enable_service: false,
args: [
'disable-infobars=true',
]
},
loggingPrefs: {
driver: 'WARNING',
server: 'WARNING',
browser: 'INFO'
},
'browserstack.user': 'xx'
'browserstack.key': 'xxx',
'browserstack.debug': true,
};
};
exports.config = {
suites: {
smoke: [
'*/*.js'
]
},
SELENIUM_PROMISE_MANAGER: false,
baseUrl: undefined,
framework: 'jasmine',
allScriptsTimeout: 100000,
getPageTimeout: 100000,
maxSessions: 1,
seleniumAddress: 'https://hub-cloud.browserstack.com/wd/hub',
getMultiCapabilities: function() {
let that = this;
return new Promise(function(resolve) {
let defaults = exports.makeDefaultCapabilities(that);
let capabilities = [];
capabilities.push({
os: 'OS X',
os_version: 'High Sierra'
});
_.forEach(capabilities, function(capability) {
_.defaultsDeep(capability, defaults);
});
resolve(capabilities);
});
},
beforeSession: function(config, capabilities, specs) {
capabilities.name = specs && specs[0].split('/').pop() || undefined;
},
onPrepare: function() {
jasmine.getEnv().addReporter(failFast.init());
let reporter = new SpecReporter();
jasmine.getEnv().addReporter(reporter);
}
};
The beforeSession hook doesn't update the test name in browserstack as the test spec name.
Looking forward for any suggestion. Appreciate your help.
Thanks
Include const request = require('request'); in the *.conf.js file and following snippet in onPrepare() function. This will get the name of your test spec and change the name using BrowserStack REST API.
jasmine.getEnv().addReporter({
specStarted: function(result) {
browser.getCapabilities().then(function (capabilities) {
browser.getSession().then(function(session){
var sessionID = session.getId()
var headers = {
'Content-Type': 'application/json'
};
var dataString = `{"name":"${result.fullName}"}`;
var options = {
url: 'https://api.browserstack.com/automate/sessions/' + sessionID + '.json',
method: 'PUT',
headers: headers,
body: dataString,
auth: {
'user': browserstackUser,
'pass': browserstackKey
}
};
function callback(error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
}
request(options, callback);
});
});
}
});

Protractor E/launcher - Process exited with error code 199

when i run gulp to start protractor i got this error
E/launcher - unknown error: cannot parse capability: proxy
from unknown error: proxyType is 'manual' but no manual proxy capabilities were found
(Driver info: chromedriver=2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73),platform=Windows NT 10.0.16299
x86_64)
protractor version 5.1.1
gulpfile
ar gulp = require('gulp');
var path = require('path');
var child_process = require('child_process');
var requireDir = require('require-dir');
requireDir('./config/gulp/tasks');
var runSequence = require('run-sequence');
var open = require('gulp-open');
gulp.task('default', [
//'complete'
'protractor-test'
]);
function getBinary(packageName, binaryLocation) {
var pkgPath = require.resolve(packageName);
return path.resolve(path.join(path.dirname(pkgPath), '..', binaryLocation));
}
gulp.task('protractor-install', function(done) {
var binary = getBinary('webdriver-manager', '../bin/webdriver-manager');
child_process.spawn('node', [binary, 'update --versions.chrome 2.29'], {
stdio: 'inherit'
}).once('close', function() {
done();
});
});
gulp.task('protractor-start', function(done) {
var binary = getBinary('protractor', 'bin/protractor');
child_process.spawn('node', [binary, 'protractor.conf.js'], {
stdio: 'inherit'
}).once('close', function() {
gulp.src('protractor-results/report.html')
.pipe(open({ app: 'chrome' }));
done();
});
});
gulp.task('t', function() {
runSequence('start-server',
'start-proxy',
'protractor-start',
'stop-servers');
});
gulp.task('debug-proxy', function(done) {
child_process.spawn('C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe', ['--proxy-server=http=localhost:8080', '--user-data-dir=C:\\tmp', 'http://localhost:49852'], {
stdio: 'inherit'
}).once('close', function() {
done();
});
});
and the config of protractor
exports.config = {
directConnect: true,
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
prefs: {
'credentials_enable_service': false,
'profile': {
'password_manager_enabled': false
}
}
},
'proxy': {
'proxyType': 'manual',
'httpsProxy': 'localhost:3000'
}
},
framework: 'jasmine',
specs: [
'Tests/Common/common-e2e-spec.js',
// 'Tests/S4B/skype4-business-e2e-spec.js',
// 'Tests/CM/client-management-e2e-spec.js',
// 'Tests/MC/manage-compute-e2e-spec.js'
],
useAllAngular2AppRoots: true,
baseUrl: 'https://localhost:44300',
beforeLaunch: function() {
return new Promise(function(resolve) {
screenshotreporter.beforeLaunch(resolve);
});
},
onPrepare: function() {
jasmine.getEnv().addReporter(screenshotreporter);
jasmine.getEnv().addReporter(xmlreporter1);
jasmine.getEnv().addReporter(xmlreporter2);
},
afterLaunch: function(exitCode) {
return new Promise(function(resolve) {
screenshotreporter.afterLaunch(resolve.bind(this, exitCode));
});
},
jasmineNodeOpts: {
//1 minute timeout
defaultTimeoutInterval: 60000,
showTiming: true,
print: function() {}
}
};
Make sure to run gulp without sudo!!!

while running the config.js file the results appear without even execution starts but the result takes nanoseconds to complete

below provided is the config file and the stepdefinition file. after running it says
2 scenarios (2 passed)
7 steps (7 passed)
0m00.001s
E/launcher - expected 'Hello Ayush!' to equal 'Hello Rahul!'
Process exited with error code 199
var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
var expect = chai.expect;
module.exports = function() {
this.Given(/^I go to "([^"]*)"$/, function(site) {
browser.get(site);
});
this.When(/^I add "([^"]*)" in the task field$/, function(task) {
element(by.model('todoList.todoText')).sendKeys(task);
});
this.When(/^I typed name in the field$/, function() {
element(by.model('yourName')).sendKeys('Ayush');
});
this.Then(/^I click the add button$/, function() {
var el = element(by.css('[value="add"]'));
el.click();
});
this.Then(/^I should see my new task in the list$/, function(callback) {
var todoList = element.all(by.repeater('todo in todoList.todos'));
expect(todoList.count()).to.eventually.equal(3);
expect(todoList.get(2).getText()).to.eventually.equal('Be Awesome');
callback();
});
this.Then(/^The name should be displayed in the greeting$/, function() {
var greeting = element(by.binding('yourName'));
expect(greeting.getText()).to.eventually.equal('Hello Rahul!');
//callback();
});
};
exports.config = {
seleniumAddress: 'http://127.0.0.1:4444/wd/hub',
getPageTimeout: 60000,
allScriptsTimeout: 500000,
framework: 'custom',
// path relative to the current config file
frameworkPath: require.resolve('protractor-cucumber-framework'),
capabilities: {
'browserName': 'chrome'
},
// Spec patterns are relative to this directory.
specs: [
'/Users/viveka1/vivek_ayush_angular_ui/feature/login.feature'
],
//baseURL: 'http://localhost:8080/',
baseURL: 'https://angularjs.org/',
cucumberOpts: {
require: '/Users/viveka1/vivek_ayush_angular_ui/step_definition/login.js',
tags: false,
format: 'summary',
profile: false,
'no-source': true
}
};
Try to add callback or return into steps.
like:
this.When(/^I add "([^"]*)" in the task field$/, function(task) {
return element(by.model('todoList.todoText')).sendKeys(task); });