Target browser must be a string... (selenium, protractor) - selenium-webdriver

i have upgraded my environment to have support for my tests for firefox, chrome, etc.
I have installed:
Node LTS (6.10.0)
Selenium Server Standalone 3.1.0
protractor#5.1.1
npm#4.1.2
When i now want to run my test i receive:
[17:31:32] I/launcher - Running 1 instances of WebDriver
[17:31:32] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
[17:31:32] E/launcher - Error: TypeError: Target browser must be a string, but is <undefined>; did you forget to call forBrowser()?
[...]
[17:31:32] E/launcher - Process exited with error code 100
Process finished with exit code 100
What does that mean?
The config.js is:
var TIMEOUT = 10000;
exports.config = {
...
capabilities: [
{
'browserName': 'firefox', //tried as 'firefox', firefox and "firefox"
//'marionette': true //tried true and false
},
],
...
};

That was tricky and funny :) You know what .. There is no issue with browserName. Problem was you are providing the capabilities object incorrectly. You are providing an array whereas you need to send 1 capabilities object
Remove '[' & ']'
capabilities: [{'browserName': 'firefox'},] - This is incorrect . This means an Array of size 1 with index 0 holding your firefox config
It should be this - capabilities: {'browserName': 'firefox'}

Related

test case execution is getting failed and it is throwing any error stack trace in command line

I created a testcase with Protractor-cucumber framework and I have used Grunt for execution of that test case. However, at the time of execution it failed and it's not providing any error stacktrace to know why it is failing.
I've searched Google and also reviewed other Stack Overflow solutions but I didn't find a solution for this.
Config File
exports.config = {
//seleniumAddress: 'http://localhost:4444/wd/hub',
getPageTimeout: 60000,
allScriptsTimeout: 500000,
directConnect:true,
framework: 'custom',
// path relative to the current config file
frameworkPath: require.resolve('C:\\...\\node_modules\\protractor-cucumber-framework'),
capabilities: {
'browserName': 'chrome'
},
ignoreUncaughtExceptions:true,
// Spec patterns are relative to this directory.
specs: [
'./learnFramework/utility/test.feature'
],
cucumberOpts: {
require: './learnFramework/TestCases/spec.js',
tags: false,
profile: false,
'no-source': true
},
onPrepare: function () {
browser.ignoreSynchronization=true;
browser.manage().window().maximize();
}
};
Spec File
module.exports=function(){
this.Given(/^Open the browser and Load the URL$/,async function(){
browser.get("https://google.com");
});
this.When(/^User entered the text in the search box$/,async function(){
browser.sleep(5000);
console.log(await browser.getTitle());
await element(By.name("q")).sendKeys("facebook");
browser.sleep(3000);
});
this.Then(/^click on search$/,async function(){
browser.action().sendKeys(protractor.Key.ENTER).perform();
browser.sleep(5000);
});
}
Error Log
Running "jshint:files" (jshint) task
>> 1 file lint free.
>
Running "protractor:singlerun" (protractor) task
[00:08:29] I/launcher - Running 1 instances of WebDriver
[00:08:29] I/direct - Using ChromeDriver directly...
>
DevTools listening on ws://127.0.0.1:50146/devtools/browser/5c09d68c-f3ff-43b2-b645-0b5c098c41d9
Feature: Title of your feature
>
I want to use this template for my feature file
>
Scenario: Title of your scenario
✓ Given Open the browser and Load the URL
✖ When User entered the text in the search box
- And click on search
>
Failures:
>
[00:09:03] I/launcher - 0 instance(s) of WebDriver still running
[00:09:03] I/launcher - chrome #01 failed 1 test(s)
[00:09:03] I/launcher - overall: 1 failed spec(s)
[00:09:03] E/launcher - Process exited with error code 1
>>>
>>> Test failed but keep the grunt process alive.
>
Done.
If you observe the error log "When" step has failed but there is no error stacktrace in the command line to find why it failed.
My expectation is that it should show the error stacktrace for why it has failed.
You need to use await on your browser actions otherwise it performs the actions synchronously.
e.g
await browser.get("https://google.com");

Trying to get TRACE level logging from Geckodriver

I'm trying to get trace logging information out of the gecko driver, in order to debug some issues we're having with moving to newer versions of Python, Robot Framework, Selenium, Firefox.
See in the DEBUG robot output below, I'm setting the capabilities to include log level arguments as part of moz:firefoxOptions.
When the capabilities are printed out for Open Browser, the moz:firefoxOptions value has been replaced with the profile info, so I never get tracing set.
20190219 13:07:22.461 - INFO - {'browserName': 'firefox', 'marionette': True, 'acceptInsecureCerts': True, 'moz:firefoxOptions': {'prefs': {'log': {'level': 'trace'}}, 'args': ['-headless', '-profile', '/tmp/tmpimda__f2']}, 'binary': '/usr/bin/firefox'}
20190219 13:07:22.461 - INFO - +--- END KW: BuiltIn.Log (1)
20190219 13:07:22.461 - INFO - +--- START KW: CustomLib.AdminClass.Open Browser [ ${LOGIN URL} | ${BROWSER} | desired_capabilities=${dc} | ff_profile_dir=${profile} ]
20190219 13:07:22.462 - INFO - Opening browser 'Firefox' to base url 'https://HOST:PORT/bmmadmin/login.jsp'.
20190219 13:07:22.480 - DEBUG - POST http://127.0.0.1:38132/session {"capabilities": {"firstMatch": [{}], "alwaysMatch": {"browserName": "firefox", "acceptInsecureCerts": true, "moz:firefoxOptions": {"profile": "UEsDBBQAAAAIAOtoU04+3NKsfgMAAM0MAAAHAAAAdXNlci5qc6VWTW/UMBC98ytQTyCx1rbABU6lFAkJUcSq4mg59mTjrmMbe7zp/nvGyaYsbb6AWz7e89hvZt44RQjcByhfnBXBNfTGlKtZo61yDVOp9gysKAyos1fPMSR4+f5ZesoxAiGEZE/ApTBxBG2hQVGwFAzhzkThEr4rjLC7sym8F1tYtn5EETB5lhmEXE+jKlfDEblgL49Z3O3p5FoBqyM6266it9YFGFmAPqkb+6MVOJ6vmbYY3O33L9Phc1Jqcc9lFSgwjzJoj5wU56jrHPT1epiwDBnAu4BcGMPvIod7CR61s3Ew6XdiL7plmetgLFau+Wyv6NEZGCRZwMaFHZOCKHtY5XjCrAiw13ImrxFkChoPTMa+HEeAj5PTgJFZr9lSm2IyoZTO5xQzizRQqECHC1zIrCBPlNsUERSXEHBYzRNSjClHfCBp+gBhhtXpwa3IsnLYgx0JJLxnySvqVCYSumEFT0CLWk3p6I04gLo+X2++OqRcEuHNCNg11jihqDAtaRzasvlRgd1k9bXdTse6vv1yyfp2m7SjFvmadVmYsy5td1THYKnsycS6JF/MYcmSOo8cB7uyJPxIpfagAEJlZQBB0k4/6RDxkrSQI230YEOihPaZVFtoiqeMWphGhKV2CiLI6lgWc1BTxuRzc/f2PuajEGO2DiSnJBXayi/J27gMIlYzUSowhskK5O4jlCIZ/ND9mabRDImMjm1v7JVxceYoJ+gbyvgwmBQRnXdmVSsQBqvunS1ytgl+8rlVrv+R3Ucvc0F9T3+/feO22/xRdp7+F/vwzmh5YPnjJhW1bvP8v/xv7cfL3w09tAzs0TkTGTmEC8eNT15f8ugjB2sNtG1rRXPGbnlWfjhG9gjbFm5roh878kYSO7vu+XoUXhgnd0ZHnK6IE0Zb4Feu9mTthTZ5AFq9rdAcZqlLLPwp3JJ/l4fb0UY6GfxTqvajvnP51dEHVzRiMcXhlXtKhUjXtkrH6rDKvz3NxJUBu8VsCRdv3/5J65emqUX5MMY1vDhw1XnC4N48WYzHmLub104Js/DmUWoD9MRc0NQWvKvRfJmawUcMWiJ/TBsKlW+NlqywhrqAsGlfR+TKZb7TyI6y9eP0WMqDB+8pCIYiYDiwTor25Bdz2EmRnsID3LXjbHAn916T7VO2WD4y1QS5PzF+Jh3GIvymNJWmMLmLBhi/AFBLAQIUAxQAAAAIAOtoU04+3NKsfgMAAM0MAAAHAAAAAAAAAAAAAACkgQAAAAB1c2VyLmpzUEsFBgAAAAABAAEANQAAAKMDAAAAAA=="}}}, "desiredCapabilities": {"browserName": "firefox", "acceptInsecureCerts": true, "moz:firefoxOptions": {"profile": "UEsDBBQAAAAIAOtoU04+3NKsfgMAAM0MAAAHAAAAdXNlci5qc6VWTW/UMBC98ytQTyCx1rbABU6lFAkJUcSq4mg59mTjrmMbe7zp/nvGyaYsbb6AWz7e89hvZt44RQjcByhfnBXBNfTGlKtZo61yDVOp9gysKAyos1fPMSR4+f5ZesoxAiGEZE/ApTBxBG2hQVGwFAzhzkThEr4rjLC7sym8F1tYtn5EETB5lhmEXE+jKlfDEblgL49Z3O3p5FoBqyM6266it9YFGFmAPqkb+6MVOJ6vmbYY3O33L9Phc1Jqcc9lFSgwjzJoj5wU56jrHPT1epiwDBnAu4BcGMPvIod7CR61s3Ew6XdiL7plmetgLFau+Wyv6NEZGCRZwMaFHZOCKHtY5XjCrAiw13ImrxFkChoPTMa+HEeAj5PTgJFZr9lSm2IyoZTO5xQzizRQqECHC1zIrCBPlNsUERSXEHBYzRNSjClHfCBp+gBhhtXpwa3IsnLYgx0JJLxnySvqVCYSumEFT0CLWk3p6I04gLo+X2++OqRcEuHNCNg11jihqDAtaRzasvlRgd1k9bXdTse6vv1yyfp2m7SjFvmadVmYsy5td1THYKnsycS6JF/MYcmSOo8cB7uyJPxIpfagAEJlZQBB0k4/6RDxkrSQI230YEOihPaZVFtoiqeMWphGhKV2CiLI6lgWc1BTxuRzc/f2PuajEGO2DiSnJBXayi/J27gMIlYzUSowhskK5O4jlCIZ/ND9mabRDImMjm1v7JVxceYoJ+gbyvgwmBQRnXdmVSsQBqvunS1ytgl+8rlVrv+R3Ucvc0F9T3+/feO22/xRdp7+F/vwzmh5YPnjJhW1bvP8v/xv7cfL3w09tAzs0TkTGTmEC8eNT15f8ugjB2sNtG1rRXPGbnlWfjhG9gjbFm5roh878kYSO7vu+XoUXhgnd0ZHnK6IE0Zb4Feu9mTthTZ5AFq9rdAcZqlLLPwp3JJ/l4fb0UY6GfxTqvajvnP51dEHVzRiMcXhlXtKhUjXtkrH6rDKvz3NxJUBu8VsCRdv3/5J65emqUX5MMY1vDhw1XnC4N48WYzHmLub104Js/DmUWoD9MRc0NQWvKvRfJmawUcMWiJ/TBsKlW+NlqywhrqAsGlfR+TKZb7TyI6y9eP0WMqDB+8pCIYiYDiwTor25Bdz2EmRnsID3LXjbHAn916T7VO2WD4y1QS5PzF+Jh3GIvymNJWmMLmLBhi/AFBLAQIUAxQAAAAIAOtoU04+3NKsfgMAAM0MAAAHAAAAAAAAAAAAAACkgQAAAAB1c2VyLmpzUEsFBgAAAAABAAEANQAAAKMDAAAAAA=="}, "binary": "/usr/bin/firefox", "marionette": true}}
Anyone have any ideas what I may be doing wrong here? And/OR some alternative methods of getting trace logging from geckodriver?
BTW: the moz:firefoxOptions I'm setting may not be correct, they're just the latest combination I have tried, but I can't tell what is going to work until the options I set are actually being sent to firefox.
Environment:
Python 3.6.3
geckodriver 0.24.0 ( 2019-01-28)
Mozilla Firefox 60.4.0
PIP:
requests (2.21.0)
robotframework (3.1.1)
robotframework-requests (0.5.0)
robotframework-selenium2library (3.0.0)
robotframework-seleniumlibrary (3.3.1)
selenium (3.141.0)
setuptools (40.8.0)
urllib3 (1.24.1)
ROBOT:
Open Browser To Login Page
${dc}= CustomLib.Get Desired Capabilities ${BROWSER}
Set To Dictionary ${dc}
... binary ${PATH TO MARIONETTE}
Log ${dc}
${profile}= CustomLib.Create FF Profile
Open Browser ${LOGIN URL} ${BROWSER} desired_capabilities=${dc} ff_profile_dir=${profile}
PYTHON:
#keyword
def get_desired_capabilities(browser):
_capabilities = {'ff' : DesiredCapabilities.FIREFOX,
'firefox' : DesiredCapabilities.FIREFOX
}
browserKey = str(browser).lower()
desired = _capabilities[browserKey]
BuiltIn().log("get_desired_capabilities B4 :" + str(desired))
#THIS IS ASSUMING FIREFOX
desired['marionette'] = True
desired['acceptSslCerts'] = True
desired['ignoreProtectedModeSettings'] = True
desired['headless'] = True
desired['moz:webdriverClick'] = True
desired['moz:firefoxOptions'] = {'log':{'level':'trace'}, 'args':['-headless']}
#desired['moz:firefoxOptions']['log'] = {'level':'trace'}
#desired['moz:firefoxOptions']['args'] = ['-headless']
BuiltIn().log("get_desired_capabilities returning :" + str(desired))
return desired
#keyword
def create_ff_download_profile(path):
from selenium import webdriver
BuiltIn().log('PATH: ' + path)
fp = webdriver.FirefoxProfile()
fp.set_preference("browser.download.folderList", 2)
fp.set_preference("browser.download.manager.showWhenStarting", False)
fp.set_preference("browser.helperApps.alwaysAsk.force", False);
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", 'text/xml,text/plain,application/octet-stream')
fp.set_preference("browser.download.dir", path)
fp.update_preferences()
return fp.path
thanks,
Tom
This is how I set the log level to be trace in Firefox:
*** Settings ***
Library SeleniumLibrary
*** Keywords ***
${options}= Evaluate sys.modules['selenium.webdriver.firefox.options'].Options() sys
${options.log.level}= Set Variable trace
${driver}= Create Webdriver Firefox options=${options}
Go To https://www.google.com
It's basically following this python pattern from the firefox docs and translating it into Robotframework
Hope this helps!

Error message [null] or [null,null,null,null] when using browser.actions protractor

When runnning code like:
element(by.css('input')).sendKeys(arg1).then(function() {
browser.actions().sendKeys(protractor.Key.ENTER).perform().then(callback);
});
Or anything using browser.actions()
I'm getting an error message like:
1) Scenario: User goes back to search results - features\headerNavigations.feature:31
Step: When I enter "1000W Rotary Lawnmower" - features\headerNavigations.feature:34
Step Definition: ..\node_modules\cucumber-tsflow\src\BindingDecorator.ts:163
Message:
[ null ]
Ever since updating to chromedriver 2.27 I'm seeing this issue.
Node: 6.9.1
Protractor: 5.1.0
Chrome: 56.0
Chromedriver: 2.27
Seen this which maybe similar:
https://github.com/angular/protractor/issues/4067
And raised a question here:
https://groups.google.com/forum/#!forum/chromedriver-users
Not seeing much action from the protractor or chromedriver community

when running protractor with phantomjs browser, only able to run tests once

test code:
describe('mysite', function(){
var init_url = 'http://localhost/mySite/#/home';
beforeEach(function(){
// driver = new webdriver.Builder().
// withCapabilities(webdriver.Capabilities.phantomjs()).build();
})
it('should click on toolbox and do stuff', function(){
browser.get(init_url);
browser.waitForAngular();
browser.getCurrentUrl().then(function(url){
console.log('current_url', url);
expect(init_url).toEqual(init_url);
})
expect(true).toBe(true);
browser.sleep(2000);
})
result 1st time run,
Using the selenium server at http://localhost:9515
data Zoom Pad
class active
mysite
should click on toolbox and do stuff
Finished in 3.94 seconds
1 test, 4 assertions, 0 failures
2nd time run, without any interruption, just up arrow and enter:
Stacktrace:
Error: Error while running testForAngular: Error Message => 'Detected a pag
e unload event; asynchronous script execution does not work across page loads.'
caused by Request => {"headers":{"Accept":"application/json; charset=utf-8","Co
nnection":"keep-alive","Content-Length":"689","Content-Type":"application/json;c
harset=UTF-8","Host":"localhost:9515"},"httpVersion":"1.1","method":"POST","post
":"{\"script\":\"return (function () {\\n var attempts = arguments[0];\\n var
callback = arguments[arguments.length - 1];\\n var check = function(n) {\\n
try {\\n if (window.angular && window.angular.resumeBootstrap) {\\n
callback([true, null]);\\n } else if (n < 1) {\\n if (window.angular
) {\\n callback([false, 'angular never provided resumeBootstrap']);\\n
} else {\\n callback([false, 'retries looking for angular exceed
third time
1) mysite should click on toolbox and do stuff
Message:
Error: ECONNREFUSED connect ECONNREFUSED
Stacktrace:
Error: ECONNREFUSED connect ECONNREFUSED
at ClientRequest.<anonymous> (K:\Users\Congwen\AppData\Roaming\npm\node_modu
les\protractor\node_modules\selenium-webdriver\http\index.js:127:16)
at ClientRequest.EventEmitter.emit (events.js:95:17)
at Socket.socketErrorListener (http.js:1547:9)
at Socket.EventEmitter.emit (events.js:95:17)
at net.js:441:14
and on third time the phantomjs webserver is down, and needs to be reconnected, and afterwards it goes back to result 1:
any clues?
config file used:
exports.config = {
seleniumAddress: 'http://localhost:9515',
specs: [
'./ptor-tests/mysite-test.js'
],
capabilities: {
browserName: 'phantomjs',
version: '',
platform: 'ANY'
},
//baseUrl: 'http://testapp.example.com/index.html',
rootElement: 'body',
allScriptsTimeout: 11000,
onPrepare: function () {},
jasmineNodeOpts: {
onComplete: function () {},
isVerbose: true,
showColors: true,
includeStackTrace: true,
defaultTimeoutInterval: 30000
}
};
also I noticed that sometimes there's no step 2 needed and it will go directly to ECONNECT error, and sometimes it gets stuck in step 2 for a number of tests and eventually will terminate phantomjs server.
This is an issue with Protractor that was resolved in version 0.17 and made better in 0.18.
It's a bug with a long tail, but the TL;DR is that Protractor's .get(url) function actually uses client-side JavaScript to make the location change; this is to ensure it properly bootstraps. An unfortunate side effect of that design is that for some reason, PhantomJS takes a few seconds to navigate over properly.
The bug was resolved by adding a longer timeout to the .get function.
Github Issue: https://github.com/angular/protractor/issues/85
Relevant changelog entries:
v0.18
(10aec0f) fix(pageload): increase wait timeout
The 300 ms wait caused problems when testing IE on Sauce Labs. It seems way too short. "browser.get()" invariably timed out. Increasing it solved our problem.
v0.17
(a0bd84b) fix(pageload): add a wait during protractor.get() to solve unload issues
Some systems would not wait for the browser unload event to finish before beginning the asynchronous script execution.
Closes #406. Closes #85.
I've run your test locally (with a different page, but otherwise the same code):
Happy testing!

Running AngularJS Protractor with proxy to https

I get the following error in the command line when trying to run Protractor:
>
Fatal error: protractor exited with code: 1
I need to proxy to an https test server. How do I accomplish this? I followed the advice from this Github issue, but I am still getting the above error. Here is my config file:
// A reference configuration file.
exports.config = {
// ----- How to setup Selenium -----
//
// There are three ways to specify how to use Selenium. Specify one of the
// following:
//
// 1. seleniumServerJar - to start Selenium Standalone locally.
// 2. seleniumAddress - to connect to a Selenium server which is already
// running.
// 3. sauceUser/sauceKey - to use remote Selenium servers via SauceLabs.
// The location of the selenium standalone server .jar file.
seleniumServerJar: './selenium/selenium-server-standalone-2.35.0.jar',
// The port to start the selenium server on, or null if the server should
// find its own unused port.
seleniumPort: null,
// Chromedriver location is used to help the selenium standalone server
// find chromedriver. This will be passed to the selenium jar as
// the system property webdriver.chrome.driver. If null, selenium will
// attempt to find chromedriver using PATH.
chromeDriver: './selenium/chromedriver',
// Additional command line options to pass to selenium. For example,
// if you need to change the browser timeout, use
// seleniumArgs: ['-browserTimeout=60'],
seleniumArgs: [],
// If sauceUser and sauceKey are specified, seleniumServerJar will be ignored.
// The tests will be run remotely using SauceLabs.
sauceUser: null,
sauceKey: null,
// ----- What tests to run -----
//
// Spec patterns are relative to the location of this config.
specs: [
'./e2e/*-spec.js'
],
// ----- Capabilities to be passed to the webdriver instance ----
//
// For a full list of available capabilities, see
// https://code.google.com/p/selenium/wiki/DesiredCapabilities
// and
// https://code.google.com/p/selenium/source/browse/javascript/webdriver/capabilities.js
capabilities: {
'browserName': 'chrome',
'proxy': {
'proxyType': 'manual',
'httpProxy': 'https://localhost.com:8443/'
}
},
// A base URL for your application under test. Calls to protractor.get()
// with relative paths will be prepended with this.
baseUrl: 'http://localhost:9999',
// Selector for the element housing the angular app - this defaults to
// body, but is necessary if ng-app is on a descendant of <body>
rootElement: 'body',
// ----- Options to be passed to minijasminenode -----
jasmineNodeOpts: {
// onComplete will be called just before the driver quits.
onComplete: null,
// If true, display spec names.
isVerbose: true,
// If true, print colors to the terminal.
showColors: true,
// If true, include stack traces in failures.
includeStackTrace: true,
// Default time to wait in ms before a test fails.
defaultTimeoutInterval: 10000
}
};
According to the WebDriver capabilities documentation, you should use 'hostname:port' as the format for the httpProxy. E.g.:
capabilities: {
browserName: 'firefox',
proxy: {
proxyType: 'manual',
httpProxy: 'localhost:8443',
sslProxy: 'localhost:8888'
}
}
Check your proxy software for the correct port.
This works in Firefox and Chrome.

Resources