Set Firefox Preferences in Nightwatch - javascript

How do you set firefox preferences in nightwatch? I would like to do the equivalent in java with nightwatch.
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("intl.accept_languages", "de");
WebDriver driver = new FirefoxDriver(profile);
I have this working in chrome, but again I can't figure out how to do it in Firefox.
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true,
"chromeOptions" :{
"prefs": {
"intl.accept_languages":"fr"
}
}
}
Thanks

The solution is to create a Firefox profile for your Nightwatch test.
1) Create a new Firefox profile:
In a terminal, execute this command : "firefox -p"
Then create a profil with the name "webdriver".
2) Configure the new profile
Go to this config page with the url : about:config
Search the name "intl.accept_languages" and update the value.
Exit Firefox for now.
3) Configure Nightwatch to use the new profile
"webdriver.firefox.profile" : "webdriver"
List item "browserName" : "firefox"
Be careful ! it is not a "desiredCapability" parameter.
Solution 1: (test config)
{
"yourTest" : {
"default" : {
...
"webdriver.firefox.profile" : "webdriver",
"launch_url": "http://localhost:3000",
"desiredCapabilities" : {
"browserName" : "firefox",
"javascriptEnabled" : true,
"acceptSslCerts" : true
}
}
}
}
Solution 2: (global config)
{
...
"selenium" : {
"start_process" : false,
"server_path" : "",
"log_path" : "",
"host" : "127.0.0.1",
"port" : 4444,
"cli_args" : {
"webdriver.chrome.driver" : "",
"webdriver.ie.driver" : "",
"webdriver.firefox.profile" : "webdriver"
}
},
...
"yourTest": {
"default": {
"launch_url": "http://localhost:3000",
"desiredCapabilities" : {
"browserName" : "firefox",
"javascriptEnabled" : true,
"acceptSslCerts" : true
}
},
...
}
...
}
check the selenium settings : http://nightwatchjs.org/guide#selenium-settings

Related

Firebase load all data from uid

Let's say I have a big list of items where the user can go and favourite items as they wish. These favourites then go to a new node userLikedItems/userUID/.
When saving favourites, I am trying to figure out the best way to do so:
Here is my current, duplicative approach:
//duplicating all the data when a user favourites an item into their own node under userLikedItems
{
"hwUjzftGyCgMrRgNv4Djg5F4ZCQ2" : {
"24K Carrot" : {
"effects" : {
"Euphoria" : true,
"Happy" : true,
"Relaxing" : true,
"Sleepy" : true
},
"medical" : {
"Arthritis" : true,
"Bipolar Disorder" : true,
"Chronic Pain" : true,
"Depression" : true,
"Fatigue" : true,
"Inflammation" : true,
"Insomnia" : true,
"Loss of Appetite" : true,
"Migraines" : true,
"PTSD" : true,
"Stress" : true
},
"levels" : "18% - 24%",
"title" : "24K Carrot",
"titleLowercase" : "24k Carrot",
"uid" : "24K Carrot"
},
"2 Pac" : {
"effects" : {
"Cerebral" : true,
"Focus" : true,
"Happy" : true,
"Horny" : true,
"Relaxing" : true,
"Uplifting" : true
},
"medical" : {
"Arthritis" : true,
"Cramps" : true,
"Depression" : true,
"Gastrointestinal Disorder" : true,
"Loss of Appetite" : true,
"Migraines" : true
},
"levels" : "29%",
"title" : "2 Pac",
"titleLowercase" : "2 pac",
"uid" : "2 Pac"
},
}
}
Here is the next approach where I am trying to determine if it is a better practice than my current approach:
//data stored with only uid:true under user's favourites node
{
"hwUjzftGyCgMrRgNv4Djg5F4ZCQ2" : {
"24K Carrot" : true,
"2 Pac" : true,
"Triple Take" : true,
}
// fetching the rest of the data inside list item
componentDidMount() {
firebase.database().ref('/userLikedItems').child(this.props.user.item.uid).once('value', snapshot => {
const itemData = snapshot.val();
this.setState({
name: itemData.name,
image: itemData.image,
type: itemData.type
});
});
}
So basically when a list item is mounted I am calling this query to fetch the rest of the data. I am worried this is a bad practice.
Right now I am currently duplicating all the item data in the userLikedItems node which means I would not have to perform that query for every item, instead I would simply load all the data from the users node - the problem with this is I have to use a cloud function to keep the data consistent when the main item changes and there is a lot of duplicate data in my database when it could instead just be a simple boolean for each item.
I appreciate all the feedback!
Cheers.

How to use Safari Technology Preview in nightwatch?

I didn't find any information on how to properly setup the nightwatch config using Safari technology preview.
I've tried something like this:
module.exports = {
"src_folders": [
"suites"
],
"output_folder": "reports",
"custom_commands_path": "commands",
"page_objects_path": "pageObjects",
"globals_path": "globals.js",
"selenium": {
"start_process": true,
"server_path": seleniumServer.path,
"host": "127.0.0.1",
"port": 4444,
"log_path": "logs",
"cli_args": {
"webdriver.chrome.driver": chromedriver.path,
"webdriver.firefox.driver": '/usr/bin/geckodriver',
"webdriver.safari.driver": '/usr/bin/safaridriver'
}
},
"test_settings": {
"default": {
"launch_url": "http://google.com",
"screenshots": {
"enabled": true,
"on_failure" : true,
"on_error" : true
},
"globals": {
"waitForConditionTimeout": 5000,
"retryAssertionTimeout": 5000
},
"desiredCapabilities": {
"browserName": "safari",
"browserVersion": "12",
"technologyPreview": true
},
"skip_testcases_on_fail": false,
"end_session_on_fail": false
}
}
};
But after execution I get this error:
{ value:
{ message: 'Could not create a session: A browser with name \'safari\' version \'12\' could not be found on the system.\nBuild info: version: \'3.13.0\', revision: \'2f0d292\', time: \'2018-06-25T15:32:19.891Z\'\nSystem info: host: \'Boostas-MacBook-Pro-5.local\', ip: \'fe80:0:0:0:100a:70f9:d6d7:cbfc%en0\', os.name: \'Mac OS X\', os.arch: \'x86_64\', os.version: \'10.13.6\', java.version: \'10.0.1\'\nDriver info: driver.version: unknown\nremote stacktrace: ',
error: 'session not created' },
status: 33 }
Note: If I set technologyPreview to false the test will be run in Safari browser.
Hope you guys can help me!
Those two options worked in my case in nightwatch.json to launch Safari Technology Preview :
"desiredCapabilities": {
"browserName": "safari",
"safari.options": {"technologyPreview": true},
}
Useful reference : https://macops.ca/using-safari-technology-preview-with-selenium-webdriver/
Hope this helps !

Nightwatch : An occurred error while retrieving a new session

In my react project, I would like to use nightwatch as testing tool. I'm actually using Nightwatch v1.0.4 and selenium-server-standalone-3.9.1.jar on windows.
And this is my config (nightwatch.json) :
{
"src_folders": [
"tests"
],
"output_folder": "reports",
"custom_commands_path": "",
"custom_assertions_path": "",
"page_objects_path": "",
"globals_path": "",
"disable_colors": false,
"test_workers": false,
"selenium": {
"start_process": true,
"host": "localhost",
"port": 4444,
"server_path": "./bin/selenium-server-standalone-3.9.1.jar",
"log_path": "./logs",
"cli_args": {
"webdriver.chrome.driver": "./bin/chromedriver"
}
},
"desiredCapabilities": {
"browserName": "chrome",
"acceptSslCerts": true
},
"test_settings": {
"default": {
"webdriver": {
"server_path": "./bin/chromedriver",
"cli_args": [
"--log",
"debug"
]
},
"disable_colors": false,
"screenshots": {
"enabled": false,
"path": ""
},
"request_timeout_options": {
"timeout": 60000,
"retry_attempts": 5
},
"default_path_prefix" : "",
"desiredCapabilities": {
"browserName": "chrome",
"acceptInsecureCerts": true
}
},
"chrome": {
"webdriver": {
"port": 9515,
"default_path_prefix": "",
"server_path": "./bin/chromedriver",
"cli_args": [
"--verbose"
]
},
"desiredCapabilities": {
"browserName": "chrome",
"loggingPrefs": {
"driver": "INFO",
"server": "OFF",
"browser": "INFO"
}
}
}
}
}
And my test file (tests/index.js):
const host = 'http://localhost:3000'
module.exports = {
'Demo test' : function (browser) {
browser
.url('http://google.com')
.waitForElementVisible('body', 1000)
.pause(5000)
.end();
}
}
When I run nightwatch, it gives me the following error:
Can anyone tell me what I'm doing wrong please ?
Your ChromeDriver version -which you've mentioned as v2.9 is pretty old.
As of the ChromeDriver download page, as per your Chrome version, you should use ChromeDriver version above 2.36 - I would recommend the latest 2.38

nightwatch: distribute test with specific firefox profile

Here is my problem: I want be abble to set firefox in specific language to run our e2e tests, and be abble to distribute them.
all verions:
Mozilla Firefox 53.0.3
Selenium 3.4.0 (from npm)
geckodriver 0.17.0 (from npm)
nightwatch.conf.js:
const seleniumServer = require('selenium-server');
module.exports = {
"src_folders": [
"test/functional/features"
],
"custom_commands_path": [
"test/functional/commands/commun",
"test/functional/commands/project"
],
"output_folder": false,
"selenium": {
"start_process": true,
"server_path": seleniumServer.path,
"port": 4444,
"cli_args": {
"webdriver.gecko.driver": "./node_modules/.bin/geckodriver"
}
},
"test_settings": {
"default": {
"selenium_port": 4444,
"selenium_host": "localhost",
"silent": true,
"screenshots": {
"enabled": false
},
"detailed_output": false,
"desiredCapabilities": {
"javascriptEnabled": true,
"acceptSslCerts": true,
"marionette": true,
"browserName": "firefox"
}
}
}
};
In general I tryed two way:
dynamically create a firefox profile, and use it.
In theorie, I can use a before(Each) and use firefox-profile. In practice it create my profile but doesn't use it.
const FirefoxProfile = require('firefox-profile');
function setProfile(browser, profile, callback) {
profile.encoded(function (encodedProfile) {
browser.options.desiredCapabilities['firefox_profile'] = encodedProfile;
callback();
});
}
function setPrefToFrench(browser, done) {
var FFprofile = new FirefoxProfile();
FFprofile.setPreference('general.useragent.locale', 'fr');
FFprofile.setPreference('intl.accept_languages', 'fr');
setProfile(browser, FFprofile, done);
}
module.exports = {
'default' : {
isLocal : true
},
beforeEach: function(browser, done) {
setPrefToFrench(browser, done);
done();
}
};
Save a profile (why not ziped) and include it in project
The same, in theorie, i just have to add it on the nightwatch.conf.js
"selenium": {
"start_process": true,
"server_path": seleniumServer.path,
"port": 4444,
"cli_args": {
"webdriver.gecko.driver": "./node_modules/.bin/geckodriver",
"webdriver.firefox.profile": "path/to/my/profile(or base64 zip)"
}
},
But all time the same, my firefox is still in english.
Does anyone whould have a solution, or maybe I made something wrong?

jsTree copy_modifier : false -- Does Not prevent node copy!

Here is my code, its supposed to prevent node copy when using ctrl key, but it still allows copy and doesn't prevent it.
I use "copy_modifier" : false as per the documentation - any idea why it doesn't work?
I am using the stable version "jsTree 1.0-rc3" downloaded via the big download button on the website only a few days ago.
$(function () {
$("#jsTree")
.jstree({
"plugins" : ["themes","html_data","ui","crrm","hotkeys","types","dnd","contextmenu"], contextmenu: {items: customMenu}
//"core" : { "initially_open" : [ "node_root" ] }
,"types" : {
"valid_children" : [ "group","unknowngroup" ],
"types" : {
"group" : {
"valid_children" : ["event"],
"start_drag" : false,
"move_node" : false,
"delete_node" : false,
"remove" : false,
"icon" : {
"image" : "layout/img/folder.png"
},
},
"unknowngroup" : {
"valid_children" : ["event"],
"start_drag" : false,
"move_node" : false,
"delete_node" : false,
"remove" : false,
"icon" : {
"image" : "http://www.veryicon.com/icon/16/System/Pleasant/Recycle%20Bin%20e.png"
},
},
"event" : {
"valid_children" : "none",
"icon" : {
"image" : "http://ouccc.objectis.net/events/aggregator/previous/event_icon.gif"
},
"start_drag" : true,
"move_node" : true,
"delete_node" : false,
"remove" : false
}
},
"dnd" : {
"copy_modifier" : false,
"drag_check" : function (data) {
return {
after : true ,
before : true ,
inside : true
};
}
}
}
}).bind("rename.jstree", function (e, data) {
if(prefix!="")
{
commitGroupRename(data.rslt.obj.attr("id").substring(11),data.rslt.new_name);
var text= prefix + data.rslt.new_name;
$("#jsTree").jstree('rename_node', data.rslt.obj, text );
prefix="";
}
}).bind("loaded.jstree", function (event, data) {
//$("#jsTree").jstree("open_all");
}).bind("dblclick.jstree", function (event) {
var node = $(event.target).closest("li");
//var data = node.data("jstree");
if ($(node).attr('rel')=="group" && prefix =='')
{
var text = $("#jsTree").jstree('get_text',node);
prefix = text.substring(0,5);
text = text.substring(5);
$("#jsTree").jstree("rename_node", node , text );
$("#jsTree").jstree("rename",node);
}
}).bind("select_node.jstree", function (node, ref_node) {
var theRealNode = $.jstree._focused().get_selected();
if (theRealNode.attr('rel')=="group")
{
$('#btnRenameSelected').attr("disabled", false);
$('#btnRenameSelected').removeClass("ui-state-disabled");
}
else
{
$('#btnRenameSelected').attr("disabled", true);
$('#btnRenameSelected').addClass("ui-state-disabled");
}
});
});
Fixed - as you can see "dnd" is actually inside "types" scope. Doh! - will accept when so allows.

Categories

Resources