I using nightwatch framework for running End-to-End test. I am able to run all the test cases successfully in chrome and IE but few tests fails for phantomjs. Test cases below error out
'Search' : function(browser) {
browser
.url('http://localhost:8001/index.html')
browser
.setValue('input[id=SearchInput-inner]', 'abc')
.click('button[id=nsnButton]')
.pause('1000')
.verify.attributeEquals('#nsnButton', 'disabled', 'true')
},
Error I get is
Testing if attribute disabled of <#nsnButton> equals "true". Element does not have a disabled attribute. - expected "true" but got: "null"
other test that fails is
.getCssProperty('#SearchInput-inner', 'border-color', function(result) {
this.verify.equal(result.value, '#ee0000');
})
Error I get is Failed [equal]: ('rgb(238, 0, 0)' == '#ee0000') - expected "#ee0000" but got: "rgb(238, 0, 0)"
How Can I handle this situation where same test works for ie and chrome but fails for phantomjs.
Thanks
Related
I have two specs in a suite. Each spec has "browser.quit()" in afterAll block.
When I run these specs as suite, first spec execute without any issue and other spec throws "Invalid session ID" exception. How to fix this issue?.
Sample script.
test1.js & test2.js are same as below
describe("test1",function(){
beforeAll(function(){
console.log("Pre-condition");
});
it("test1 scenario",function(){
browser.waitForAngualrEnabled(false);
browser.get("https://www.google.com");
});
afterAll(function(){
browser.quit();
});
});
Protractor version : 7.0.0
conf.js
exports.config={
framework:'jasmine',
directConnect: false,
suites:{
test:["test1.js","test2.js"]
}
}
When these specs are run individually, it executes without any issues. I need each spec in suite has to launch and quit browser.
I don't understand why are you surprised about this error, if your script is:
console.log("Pre-condition");
browser.waitForAngualrEnabled(false);
browser.get("https://www.google.com");
browser.quit(); // close browser!!! <------------------
run spec 2, but the browser is closed at this time
Don't close the browser after the spec 1 is completed
I've recorded a test using Selenium IDE and am submitting the generated .side file to selenium-side-runner to run on a Selenium Grid built using Zalenium. Is it possible to run a command that calls driver.manage().addCookie() from the test that was submitted to selenium-side-runner? I want to do this to send messages back to Zalenium with test progress and status
I added a command executeScript to the Selenium IDE editor with a target of driver.manage().addCookie({name: 'test', value: 'test'})
I see that the command that selenium-side-runner generated in commons.js was
await driver.executeScript(`driver.manage().addCookie({name:'test', value: 'test'});`);
Doing this causes the browser to report an error JavascriptError: javascript error: driver is not defined
I think what I need is the code to be generated without the driver.executeScript wrapper. Is there a way to accomplish this without exporting my Selenium IDE test to NUnit?
I was able to make this functionality work by crudely modifying the selenium-side-runner package on my Windows dev machine
In file ~\node_modules\selenium-side-runner\node_modules\selianize\dist\selianize.cjs.js
Change
function generateScript(script, isExpression = false) {
return `await driver.executeScript(\`${isExpression ? `return (${script.script})` : script.script}\`${script.argv.length ? ',' : ''}${script.argv.map(n => `vars["${n}"]`).join(',')});`;
}
to
function generateScript(script, isExpression = false) {
if (script.script.indexOf('zalenium') > -1)
{
return script.script;
} else
{
return `await driver.executeScript(\`${isExpression ? `return (${script.script})` : script.script}\`${script.argv.length ? ',' : ''}${script.argv.map(n => `vars["${n}"]`).join(',')});`;
}
}
Now when running a test with selenium-side-runner, calling "executeScript" with any value that contains zalenium will generate the command verbatim in the test script
I am running TestCafe version 0.22.0 on Win10. I am not sure if my issue has something with the Win10 or not but unfortunately, I don´t have another computer to test on. The issue is that my tests fail with error message "GetBposShellInfoNavBarData failed: SyntaxError: Unexpected end of JSON input"
Here is the simple code I use:
Error on page "https://outlook.live.com/mail/inbox": GetBposShellInfoNavBarData failed: SyntaxError: Unexpected end of JSON input
Browser: Chrome 69.0.3497 / Windows 10.0.0
await t.click('body > section > div > div > nav > div > div > div > a');
await t.typeText('#i0116', login);
await t.click('#idSIButton9');
await t.typeText('#i0118', password);
await t.click('#idSIButton9');
await t.maximizeWindow();
Test fails on this t.maximizeWindow(). It also fails with same error on next "t.click(Selector...) if I comment out t.maximizeWindow() line.
As #ioseph properly mentioned, this error occurs on your web page and is not related to TestCafe.
I recommend that you address this error on your website and run your tests again.
Alternatively, you can use the --skip-js-errors argument to ignore such errors.
I'm using selenium-server version 3.0.1 and nightwatch version ^0.9.12 on node 8.9.0. My e2e test do run, clicks work, and reading the DOM works, but setValue just doesn't.
For example, the following test:
browser
.url("...")
.waitForElementPresent('select[name=foo]', 5000)
.click('select[name=foo] option:nth-child(2)')
.waitForElementPresent('input[name=bar]', 5000)
.setValue('input[name=bar]', "hello world")
.getValue('input[name=bar]', function(input) {
this.assert.equal(input.value, "hello world");
})
.end();
will open the url, wait for foo and click the second option. It will wait for bar, then fails:
Running: test
✔ Element <select[name=foo]> was present after 24 milliseconds.
✔ Element <input[name=bar]> was present after 28 milliseconds.
✖ Failed [equal]: ('' == 'hello world') - expected "hello world" but got: ""
at Object.<anonymous> (/test/e2e/specs/test.js:49:21)
FAILED: 1 assertions failed and 2 passed (4.692s)
_________________________________________________
TEST FAILURE: 1 assertions failed, 2 passed. (4.9s)
✖ test
- run through apply process (4.692s)
Failed [equal]: ('' == 'hello world') - expected "hello world" but got: ""
If I replace the setValue with a delay and enter a value by hand, the test will pass, so getValue is working.
This does run, and pass, on other systems, but I can't get it working on my own so I think it's a selenium-server issue.
I've tried a lot of the 101 fixes, clearing the npm cache, re-running an npm install, etc. But with no errors other than the failure, how do I debug this?
Assuming you are trying to test using Chrome, you need to update your ChromeDriver.
Chrome 65 was released recently and older ChromeDriver versions are apparently incompatible with it.
Download the latest one from the downloads page.
Make Nightwatch use it, nightwatch.json -
{
...
"selenium": {
...
"cli_args": {
"webdriver.chrome.driver": "path/to/chromedriver.exe"
Assuming Nightwatch uses it (you can see which one it uses using the Windows Task Manager - assuming you are using Windows - look for the command line of chromedriver.exe), setValue should now work again.
The error says it all :
Failed [equal]: ('' == 'hello world') - expected "hello world" but got: ""
In your code block you have induced wait for the WebElement identified as 'input[name=bar]' and next invoked setValue() which is successful as follows :
.waitForElementPresent('input[name=bar]', 5000)
.setValue('input[name=bar]', "hello world")
Now the JavaScript associated with this WebElement identified as 'input[name=bar]' will require some time to render the value within the HTML DOM. But in you code block you are trying to access the entered value (in the previous step) too early. Hence your script finds <null> as the value.
Solution
You need to induce a waiter i.e. expect clause for the value to be rendered within the HTML DOM through the associated JavaScript as follows :
.waitForElementPresent('input[name=bar]', 5000)
.setValue('input[name=bar]', "hello world")
.expect.element('input[name=bar]').to.have.value.that.equals('hello world');
.getValue('input[name=bar]', function(input) {
this.assert.equal(input.value, "hello world");
})
I am testing with Selenium-rc 1.0.3 and I am getting a Permission denied error message in IE when I run my IDE script from the command line.
I am trying to run an IDE script in Internet explorer using the selenium control RC 1.0.3
from the command line:
java -jar selenium-server.jar -htmlsuite "*iexploreproxy" "url
address/where" "C:\Users\sat\Documents\selenium\suite.html"
"C:\Users\sat\Documents\selenium scripts\results.htm" at this point
The IE window pops up saying as below
I get a security warning saying "Do you want to view only the webpage content that was delivered securely?" I hit Yes and I see this error in the test runner window:
Webpage error details
Message: Access is denied.
Line: 177
Char: 9
Code: 0
URI: xx.xx.xx.xxx/selenium-server/core/scripts/selenium-testrunner.js
UPDATE:
I looked at the line 177 and char :9 in the script and it points to
var runInterval = 0;
/** SeleniumFrame encapsulates an iframe element */
var SeleniumFrame = classCreate();
objectExtend(SeleniumFrame.prototype, {
initialize : function(frame) {
this.frame = frame;
addLoadListener(this.frame, fnBind(this._handleLoad, this));
},
getWindow : function() {
return this.frame.contentWindow;
},
getDocument : function() {
return this.frame.contentWindow.document; - line 177 char 9
},
_handleLoad: function() {
this._attachStylesheet();
this._onLoad();
if (this.loadCallback) {
this.loadCallback();
}
Do you know what the error is about? Why do I get that? I see my test cases and everything in the test runner window, but I can't run them in the IE browser. I searched the web with no avail.
I do not have much experience with running the test from CLI, but have you tried starting Selenium RC with administrator permission?
Any particular reason for not using the new Selenium 2 IWebDriver and a test framework?
The error might be caused by the use of iframe/frameset and IE's security settings. Default settings are that, if a site uses iframe/frameset and the frame content originates from 2 different root domains, then this is a security risk. Try is add the sites to your list thrusted site for IE. Have you tried to ude the firefox driver instead (will not have this security restriction).