Why error Connection refused! Is selenium server started? - selenium

Trying to run nightwatch after following this: https://github.com/dwyl/learn-nightwatch. This is my config file:
//require('env2')('.env'); // optionally store youre Evironment Variables in .env
const seleniumServer = require("selenium-server");
//const chromedriver = require("chromedriver");
const SCREENSHOT_PATH = "./screenshots/";
// we use a nightwatch.conf.js file so we can include comments and helper functions
module.exports = {
"src_folders": [
"tests/"// Where you are storing your Nightwatch e2e tests
],
"output_folder": "./reports", // reports (test outcome) output by nightwatch
"selenium": {
"start_process": true, // tells nightwatch to start/stop the selenium process
"server_path": seleniumServer.path,
"host": "127.0.0.1",
"port": 4444, // standard selenium port
"cli_args": {
"webdriver.chrome.driver": "./chromedriver.exe"
}
},
"test_settings": {
"default": {
"screenshots": {
"enabled": true, // if you want to keep screenshots
"path": './screenshots' // save screenshots here
},
"globals": {
"waitForConditionTimeout": 5000 // sometimes internet is slow so wait.
},
"desiredCapabilities": { // use Chrome as the default browser for tests
"browserName": "chrome"
}
},
"chrome": {
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true // turn off to test progressive enhancement
}
}
}
}
function padLeft(count) { // theregister.co.uk/2016/03/23/npm_left_pad_chaos/
return count < 10 ? '0' + count : count.toString();
}
var FILECOUNT = 0; // "global" screenshot file count
/**
* The default is to save screenshots to the root of your project even though
* there is a screenshots path in the config object above! ... so we need a
* function that returns the correct path for storing our screenshots.
* While we're at it, we are adding some meta-data to the filename, specifically
* the Platform/Browser where the test was run and the test (file) name.
*/
function imgpath(browser) {
var a = browser.options.desiredCapabilities;
var meta = [a.platform];
meta.push(a.browserName ? a.browserName : 'any');
meta.push(a.version ? a.version : 'any');
meta.push(a.name); // this is the test filename so always exists.
var metadata = meta.join('~').toLowerCase().replace(/ /g, '');
return SCREENSHOT_PATH + metadata + '_' + padLeft(FILECOUNT++) + '_';
}
module.exports.imgpath = imgpath;
module.exports.SCREENSHOT_PATH = SCREENSHOT_PATH;
When I run nightwatch --config conf.js, I get this error:
Starting selenium server... started - PID: 6296
[Go] Test Suite
===================
Running: Guinea Pig Assert Title
Error retrieving a new session from the selenium server
Connection refused! Is selenium server started?
{ value:
{ message: 'Unable to create new service: ChromeDriverService\nBuild info: version: \'3.8.1\', revision: \'6e95a6684b\', time: \'2017-12-01T19:05:32.194Z\'\nSystem info: host: \'S0026COW1983\', ip: \'10.39.13.81\', os.name: \'Windows Server 2008 R2\', os.arch: \'x86\', os.version: \'6.1\', java.version: \'1.8.0_131\'\nDriver info: driver.version: unknown',
error: 'session not created' },
status: 33 }

This line "webdriver.chrome.driver": "chromedriver_Win32.zip" is pointing to the zip file, you need to unzip the content and point to the exe file instead.

Related

karate-dsl: options --window-size and --incognito is not working for chromeDriver

Both the options --window-size or --incognito are not working with chromedriver. However the same options works perfectly with type chrome. I tried option --start-maximized but this also not working. I have maintained the driver configutation in karate-config.js.
function fn() {
let env = karate.env;
karate.configure('ssl', true);
karate.log('karate.env system property was:', env);
if (!env) {
//Java function to read browser value from properties
env = Java.type('examples.users.utilities.ConfigReader').read("app.target.browser").trim();
}
const config = {
env: env,
};
switch (env) {
case "chrome":
//Java function to get screen resolution/dimension
//Java function to get screen chrome driver file path
karate.configure('driver', {
type: 'chromedriver',
executable: Java.type('examples.users.utilities.Miscellaneous').getDriverFilePath() + "chromedriver.exe",
addOptions: ["--window-size=\"" + Java.type('examples.users.utilities.Miscellaneous').getWindowResolution() + "\"", "--disable-extensions"]
});
break;
case "firefox":
karate.configure('driver', {
type: 'firefox',
addOptions: ["--incognito", "--window-size=\"" + Java.type('examples.users.utilities.Miscellaneous').getWindowResolution() + "\"", "--disable-extensions"]
});
break;
default:
karate.log('Given browser is not present');
}
return config;
}
Here the Feature file.
Feature: Launch browser example 1
Scenario: Open google and enter text to search
Given driver 'https://www.google.com'
When input("input[type=text]", 'karate')
And submit()
Below are folder structure and complete source can be found here.
As far as I know, those options only work for chrome. This is an area where we welcome contributions and research.
Also see: https://stackoverflow.com/a/62700642/143475

How to declare appium driver globally in karate config.js with desired capabilities?

I am trying to declare and luanch appium driver session from config.js along with desired capabilities but i am not able to launch the driver session.
My feature file looks like below: (before declaring in config.js)
Background: Driver setup
* configure driver = { type: 'android', webDriverUrl: 'http://localhost:4723/wd/hub', start: false}
* driver { webDriverSession: { desiredCapabilities : "#(desiredConfig)" } }
Scenerio: perform click
* click('elementPath')
Added below lines in config.js then i removed first line from feature file, it worked fine.
karate.configure('driver', { type: 'android', start: false, webDriverUrl: 'http://localhost:4723/wd/hub' });
Then after that my feature file looks like below:
Background: Driver setup
* driver { webDriverSession: { desiredCapabilities : "#(desiredConfig)" } }
Scenerio: perform click
* click('elementPath')
Now i am stuck in moving the
* driver { webDriverSession: { desiredCapabilities : "#(desiredConfig)" } }
driver session part (above one) to config.js
Tried below things:
Created driver variable in config.js and assigned
{ webDriverSession: { desiredCapabilities : desiredConfig } }
Tried using driver variable in feature file
Declared desired config json directly and no luck

Javascript evaluation failed: input('#login_field','dummy') on running karate feature

I am getting error
"java.lang.AssertionError: failed features:
feature.demo-01: demo-01.feature:16 - javascript evaluation failed: input('#login_field','dummy'), ReferenceError: "input" is not defined in at line number 1"
on running the below feature
Feature: browser automation 1
Background:
* configure driver = { type: 'chrome', showDriverLog: true }
# * configure driverTarget = { docker: 'justinribeiro/chrome-headless', showDriverLog: true }
# * configure driverTarget = { docker: 'ptrthomas/karate-chrome', showDriverLog: true }
* configure driver = { type: 'chromedriver', showDriverLog: true }
# * configure driver = { type: 'geckodriver', showDriverLog: true }
# * configure driver = { type: 'safaridriver', showDriverLog: true }
# * configure driver = { type: 'iedriver', showDriverLog: true, httpConfig: { readTimeout: 120000 } }
Scenario: try to login to github and then do a google search
Given driver 'https://github.com/login'
And input('#login_field','dummy')
And input('//input[#id='password']', 'world')
You must be on an old version of Karate. Use 0.9.5.
Maybe try the ZIP Release first and get familiar: https://github.com/intuit/karate/wiki/ZIP-Release

Codeception seeInDatabase() not working as expected

I have problems getting codeceptions seeInDatabase() to work. This is my Cest:
public function testContactMailCheckbox(AcceptanceTester $I) {
$I->scrollTo("#adminMailSettingsForm", 0, -200);
$I->seeInDatabase("pib_users", [
"user_email" => "admin-cest#example.org",
"user_receive_contact_notification" => 0
]);
$I->click("//label[#for='contactMailNotification']", "#adminMailSettingsForm");
$I->waitForJS("return $.active == 0;",10);
$I->wait(100);
$I->seeInDatabase("pib_users", [
"user_email" => "admin-cest#example.org",
"user_receive_contact_notification" => 1
]);
}
The first seeInDatabase() passes, everything is fine. I can verify that this seeInDatabase-Assertion works correctly, by changing the default-data in my database dump. When I change the default data to "user_receive_contact_notification" => 1, the first seeInDatabase fails, which means it is working correctly.
I use $I->wait(100) to verify, that there are no synchronisation-issues. During this timespan I can check via phpMyAdmin, that the row was indeed updated correctly. That means the test should pass.
Here is my Db-config:
actor: AcceptanceTester
modules:
enabled:
- WebDriver:
url: 'http://pib.local/'
window_size: false # disabled in ChromeDriver
port: 5555
browser: chrome
capabilities:
chromeOptions:
args: ["--headless", "--no-sandbox", "--disable-gpu", "--window-size=1920,1080"]
- \Helper\Acceptance
- Sequence
- \Helper\DbHelper
config:
\Helper\DbHelper:
user: "root"
password: ""
dsn: "mysql:host=localhost;dbname=pib"
cleanup: true
dump: 'tests/database_dump_tests.sql'
populate: true
reconnect: true
step_decorators: ~
My DbHelper contains only a single function:
class DbHelper extends \Codeception\Module\Db
{
public function putInDatabase($table, $data, $insertOnlyIfNotExisting = true) {
// if ignoreDuplicateError is true, only execute insert when not existing already
if($this->countInDatabase($table, $data) == 0 | !$insertOnlyIfNotExisting) {
$this->_insertInDatabase($table, $data);
}
}
}
This might be related to this question. I don't use Laravel though, so just using the seeRecord()-helper isn't going to help me.

How to allow protractor test to register custom protocol handler in chrome

When I register a custom protocol handler by executing script with browser.executeScript(navigator.registerProtocolHandler(protocol, url, title)); a little icon appears in the address bar that has to be clicked and I have to choose option "allow" (ignore is by default);
but how to do that with protractor ?
I know that chrome options can be set through chromeOptions object in conf file
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
'args': ['']
}
}
but which option from this list is suitable for my problem
https://peter.sh/experiments/chromium-command-line-switches/
or maybe there is other solution?
I think I figured it out; try this:
capabilities: {
'browserName' : 'chrome',
'chromeOptions' : {
args: [],
prefs : {
custom_handlers : {
'enabled' : true,
'registered_protocol_handlers' : [
{
'default' : true,
'protocol' : '',
'title' : '',
'url' : ''
}
]
}
}
}
}
Obviously fill in the protocol, url and title as applicable.