I have the following nightwatch test:
module.exports = {
'Set Initial Dataset' : function (browser) {
browser
.url('http://localhost/nightwatch/load-initial-dataset')
.end()
}
}
When I execute it the browser is opened and the url is loaded, but when the loading is ended it doesn't close the browser to begin the next test.
The test worked 1 month ago... I updated nightwatch to the nigthwatch latest version (v0.9.8), downloaded selenium-server-standalone-3.0.1.jar, chromedriver 2.25 and Chrome 54.0.2840.87
My Nigthwatch.js is
module.exports = {
src_folders: ['./tests'],
output_folder: './results',
selenium: {
start_process: true,
server_path: './selenium-server-standalone-3.0.1.jar',
log_path: './results',
host: '127.0.0.1',
port: 4444,
"cli_args" : {
"webdriver.chrome.driver" : "./osx/chromedriver"
}
},
test_settings: {
default: {
waitForConditionPollInterval: 1,
selenium_host: '127.0.0.1',
selenium_port: 4444,
screenshots: {
enabled: true,
path: './results/screenshots'
},
desiredCapabilities: {
browserName: 'chrome',
javascriptEnabled: true,
acceptSslCerts: true
}
}
}
};
I tried to launch this test and I have the same problem: https://github.com/nightwatchjs/nightwatch/blob/master/examples/tests/google.js (the browser stay opened at the url and nothing from the terminal)
I have no particular problem when I ran my test with safari.
Thx
From a first glance it looks like your test doesn't actually perform any assertions and thus doesn't actually 'test' for anything. This might be confusing the test runner.
My other theory is that the waitForConditionPollInterval setting is too low. 1 millisecond seems a bit overkill.
Two things to do from here:
Perform an actual assertion inside your test. For example, after navigating to the page try this...
Example:
module.exports = {
'Set Initial Dataset' : function (browser) {
browser
.url('http://localhost/nightwatch/load-initial-dataset')
.assert.title('Some Title')
.end()
}
}
Remove the waitForConditionPollInterval setting and see if that helps. If it does, try setting it to something a little more sane, like 100ms, and check if the test still hangs.
My experience has been that selenium hangs when a verification isn't performed. You're not getting any output because navigating isn't a "verification" step.
While you can check for the page title to confirm that you've hit the correct url, I would consider that a bit brittle. If the page title changes for any reason it would fail your test, even if the URL you navigated to was correct. To test that you're hitting the correct url, try using .urlContains(); instead.
Example:
module.exports = {
'Set Initial Dataset' : function (browser) {
browser
.url('http://localhost/nightwatch/load-initial-dataset')
.verify.urlContains('/load-initial-dataset')
.end();
}
}
You're also missing the semi-colon after .end(); which might not be telling nightwatch the test case is actually complete.
Maybe try that, too.
Related
My colleague & I are running the same Cypress test suite on our machines, but getting different results.
The version of Cypress we are using is 3.8.3.
When they run .\node_modules\.bin\cypress run, all tests are passing.
But when I try to run the same command on my machine, one of the tests is failing.
I get the below error message:
<failure message="cy.type() can only be called on a single element.
Your subject contained 8 elements." type="CypressError">
<![CDATA[CypressError: cy.type() can only be called on a single element. Your subject contained 8 elements.
I can understand what the test is saying, but I don't know why we are getting different results on different machines when running the same tests.
One difference I can spot is that they have the option to run tests on Chrome, while I only have the option to run on Electron.
Can someone please help to explain what is causing this issue, & how it can be resolved
Cypress automatically detects browsers installed on your local machine. So please check if you have chrome installed. Electron comes directly with cypress.
The application behavior can vary from machine to machine and also from browser to browser depending on the configurations and also on the internet speed. So its always good to use Test Retries which will retry the test as per the defined value before finally marking the test as fail. Test retries were introduced in cypress 5.0.
You can apply them globally through your cypress.json
{
"retries": {
// Configure retry attempts for `cypress run`
// Default is 0
"runMode": 2,
// Configure retry attempts for `cypress open`
// Default is 0
"openMode": 0
}
Or, you can also add it to a specific test -
describe('User sign-up and login', () => {
// `it` test block with no custom configuration
it('should redirect unauthenticated user to sign-in page', () => {
// ...
})
// `it` test block with custom configuration
it(
'allows user to login',
{
retries: {
runMode: 2,
openMode: 1,
},
},
() => {
// ...
}
)
})
Or to a specific test suite as well -
// Customizing retry attempts for a suite of tests
describe('User bank accounts', {
retries: {
runMode: 2,
openMode: 1,
}
}, () => {
// The per-suite configuration is applied to each test
// If a test fails, it will be retried
it('allows a user to view their transactions', () => {
// ...
}
it('allows a user to edit their transactions', () => {
// ...
}
})
I’ve been trying without success to change default language of browsers Chromium and Firefox (inside automated tests that run in parallel using CodeceptJS + Playwright as runner) to french language. In Chromium, I’ve tried to use args --lang without success and I’ve also tried to use prefs: intl.accept_languages. In Firefox, I’ve tried to use firefoxUserPrefs. Untill now, nothing has worked.
Does anybody know how to change default language in browser launched using playwright?
CodeceptJS version 3.0.6
Playwright version 1.10.0
Chrome version 90.0.4430.0
Firefox version 87.0b10
codecept.conf.js - full printscreen
codecept.conf.js
Playwright: {
url: process.env.baseUrl || DEFAULT_HOST,
show: true,
browser: 'chromium',
waitForAction: 250,
waitForNavigation: 'networkidle0',
chromium: {
channel: process.env.BROWSER,
args: ['--lang=fr-CA'],
prefs: {
'intl.accept_languages': 'fr-CA',
},
firefoxUserPrefs: {
'intl.accept_languages': 'fr-CA, fr',
},
},
},
browser.NewContext has an option called locale. You can use that option to change the language.
This might not have been available by the time of this question, but now there are emulation options for locale (and timezone) in Playwright (documentation here).
Can be specified both globally in config, per project, like this (in playwright.config.ts):
...
projects: [
{
name: 'chromium',
use: {
...devices['Desktop Chrome'],
locale: 'fr-CA',
},
},
...
or per test, like this:
test.use({
locale: 'sv-SE',
});
test('Lang test 1', async ({ page }) => {
// Test code
});
I am currently running with Chrome 74 and trying to use Cypress to test a style-guide in my app. When I load up Cypress it throws this error:
SecurityError: Blocked a frame with origin "http://localhost:3000"
from accessing a cross-origin frame.
Please let me know if there is a solution to this!
I had tried to follow along with this:
https://github.com/cypress-io/cypress/issues/1951
But nothing has changed/worked for me. :(
My code is shown below: cypress/plugins/index.js
module.exports = (on, config) => {
on('before:browser:launch', (browser = {}, args) => {
// browser will look something like this
// {
// name: 'chrome',
// displayName: 'Chrome',
// version: '63.0.3239.108',
// path: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
// majorVersion: '63'
// }
if (browser.name === 'chrome') {
args.push('--disable-site-isolation-trials');
return args
}
if (browser.name === 'electron') {
args['fullscreen'] = true
// whatever you return here becomes the new args
return args
}
})
}
in my cypress/support/index.js
This will load the site before every test I run to save myself from having to write cy.visit in every test.
beforeEach(() =>{
cy.visit('http://localhost:3000/style-guide')
})
I had the very same issue yesterday and the answer from #jsjoeio in the cypress issue #1951 you've referenced in your question actually helped me.
So basically only thing I've done was to modify my cypress.json and add following value:
{
"chromeWebSecurity": false
}
You can disable security to overcome this issue.
Go to cypress.json file.
Write { "chromeWebSecurity": false } and save.
Run the test again.
I had exactly the same problem, I advise you to do as DurkoMatko recommends. Documentation chromeWebSecurity
But I encountered another problem with a link pointing to localhost in an iframe.
If you want to use a link in an iframe I recommend this :
cy.get('iframe').then((iframe) => {
const body = iframe.contents().find('body');
cy.wrap(body).find('a').click();
});
I have also faced this issue. My application was using service workers. Disabling service workers while visiting a page solved the issue.
cy.visit('index.html', {
onBeforeLoad (win) {
delete win.navigator.__proto__.serviceWorker
}
})
Ref: https://glebbahmutov.com/blog/cypress-tips-and-tricks/#disable-serviceworker
So, at least for me, my further problem was an internal one with tokens, logins, etc. BUT!
the code I posted for how the index in the plugin folder is correct to bypass the chrome issue. That is how you want to fix it!
Goto your cypress.json file.
Set chrome web security as false
{
"chromeWebSecurity": false
}
To get around these restrictions, Cypress implements some strategies involving JavaScript code, the browser's internal APIs, and network proxying to play by the rules of same-origin policy.
Acess your project
In file 'cypress.json' insert
{
"chromeWebSecurity": false
}
Reference: Cypress Documentation
My protractor tests were working perfectly fine yesterday on Chrome Browser.
Today, it started failing consistently at a point where in I resolve a Promise. On debugging further, I found that if I commented this promise statement then it would hang at the next promise resolution statement.
There has been no change in the protractor scripts between yesterday and today. There has been some changes made by the developers in the Angular app under test but not major ones.
Can anyone help me point out what might be going wrong here?
Following is the code snippet. Its hanging at the promise resolution statement template.getTemplatesCount().then :-
mainMenu.clickTemplatesMenuOption();
templatePage.getTemplatesCount().then(count => {
console.log("Count of template card is:-"+count.toString());
templateCountBeforeInsert = count;
});
templatePage.openCreateTemplatePanel();
createTemplatePage.createTemplateWithoutDocument(templateName);
My protractor conf.json looks like this:-
exports.config = {
allScriptsTimeout: 30000000,
specs: [
'./e2e/TestPlan/*.ts'
],
capabilities: {
'browserName': 'chrome'
},
directConnect: true,
baseUrl: 'http://10.37.1.86:81/',
getPageTimeout: 120000,
framework: 'jasmine2',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 120000,
print: function () { }
}
Following are the versions of Tools I am using:-
Protractor:- 5.1.2
ChromeDriver:- `2.32
Chrome Browser :- 61.x
You should be passing a function to your .then() block, it should be this:
templatePage.getTemplatesCount().then((count) => {
console.log("Count of template card is:-"+count.toString());
templateCountBeforeInsert = count;
});
A simple way is add catch() as below:
templatePage.getTemplatesCount().then(count => {
console.log("Count of template card is:-"+count.toString());
templateCountBeforeInsert = count;
})
.catch(function(err){
console.log('getTemplatesCount error: ' + err);
});
If you get the error log, please check getTemplatesCount() inside.
I've got some js code in a chrome background extension of the following :
function handleCapture(stream) {
console.log('content captured');
console.log("backround.js stream: ", stream);
alert(stream);
// localStream = stream; // used by RTCPeerConnection addStream();
// initialize(); // start signalling and peer connection process
}
function captureCurrentTab() {
console.log('reqeusted current tab');
chrome.tabs.getSelected(null, function(tab) {
console.log('got current tab');
var selectedTabId = tab.id;
chrome.tabCapture.capture({
audio : false,
video : true
}, handleCapture);
});
}
However, when this is ran, the "handleCapture" variable "stream" that is passed in is always undefined? Is this to be expected or is there something that I am missing here?
Also, I've confirmed that my manifest.json contains the capture permission and I am using chrome canary Version 31.0.1607.1 canary Aura.
Thanks,
Mike
I had this same issue when I was trying to drive a tabCapture purely from a background script, I found this on the tabCapture reference page:
Captures the visible area of the currently active tab. This method can only be used on the currently active page after the extension has been invoked, similar to the way that activeTab works. Note that Chrome internal pages cannot be captured.
My understanding is that this means you need to drive it from a browserAction for your extension, like so:
chrome.browserAction.onClicked.addListener(function(request) {
chrome.tabs.getSelected(null, function(tab) {
chrome.tabCapture.capture({audio: true, video: true}, callback);
});
});
That's what worked for me.
You should probably provide some constraints to make it work. See:
http://developer.chrome.com/extensions/tabCapture.html#type-MediaStreamConstraint
The capture param you provided is a MediaTrackConstraint, see:
http://dev.w3.org/2011/webrtc/editor/getusermedia.html#mediastreamconstraints
that is also a simple JS object, where you should set some mandatory options, see:
http://dev.w3.org/2011/webrtc/editor/getusermedia.html#idl-def-MediaTrackConstraints
So the following should help, if you set all the needed settings in mandatory object:
chrome.tabCapture.capture({
audio : false,
video : true,
videoConstraints: {
mandatory: {
width: { min: 640 },
height: { min: 480 }
}
}
}, handleCapture);