I have to get the url and open it in 3 new tabs. But I get errors while trying:
browser.getCurrentUrl().then(url => {
browser.actions().keyDown(protractor.Key.CONTROL).sendKeys('t').perform();
browser.sleep(2000);
browser.getAllWindowHandles().then(function (handles) {
browser.switchTo().window(handles[ 1 ]); // 0 or 1 to switch between the 2 open windows // //
browser.get(url)
});
});
Error: Failed: null value in entry: name=null
These are limitation with chrome driver to simulate the same behavior at browser level. It means sendKeys doesn't work with opening new tab as you are trying in your code. There is an alternative way to achieve your goal by 'window.open()'. here is your code snippet with small modification. hope this helps you.
browser.getCurrentUrl().then(url => {
browser.executeScript('window.open()').then( () => {
browser.sleep(2000);
browser.getAllWindowHandles().then(function (handles) {
browser.switchTo().window(handles[ 1 ]); // 0 or 1 to switch between the 2 open windows // //
browser.get(url);
});
});
});
Related
Cypress overwrite: I would like to overwrite the existing visit command so that it still operates as is, but will attempt to dismiss a popup after the visit has successfully executed.
The popup is something we have very little control over and it appears after you login. Seeing as we're bypassing the login screen and logging in programmatically, we'll see the popup when we navigate to any page. The insufficient code I currently have:
Cypress.Commands.overwrite('visit', (originalFn, url, options) => {
originalFn(url, options);
cy.get("body").then($body => {
if ($body.find("[text='Got it']").length > 0) {
cy.contains("Got it", { matchCase: false }).click();
}
});
});
Thanks
You can do this by overwriting cy.visit() command. Try this:
Cypress.Commands.overwrite('visit', (originalFn, url, options) => {
originalFn(url, options);
// make sure to add a return here!
return cy.get('body').then($body => {
if ($body.find("[text='Got it']").length > 0) {
cy.contains('Got it', { matchCase: false }).click();
}
});
});
source: https://docs.cypress.io/api/cypress-api/custom-commands#Overwrite-visit-command
I'm writing Chrome devtools plugin.
devtools.js
chrome.devtools.panels.create("Override Debug",
null,
"panel.html",
(panel) => {
panel.onShown.addListener(addDebugger);
panel.onHidden.addListener(destroyDebugger);
}
);
So when user navigates to Override Debug tab in devtools, I'm initializing debugger.
When user navigating away from my devtool, I'm discarding debugger - Which is working great
Now the issue comes, when user navigates to Override Debug and closed devtools completely, debugger still alive making page un responsive.
I tried to see events in panel object chrome.devtools objects also tried entire github to see if we have such event. No luck.
Is there any event that monitors devtools close event to discard the debugger I attached?
Update 1
Tried to attach Inspector.enable command as follows but no luck. It never got Inspector.detached message
function addDebugger() {
chrome.tabs.getSelected(null, function(target) {
debuggee = { tabId: target.id };
chrome.debugger.attach(debuggee, "1.2", () => {
chrome.debugger.sendCommand(debuggee, "Network.setRequestInterception", { patterns: [{ urlPattern: '*' }] });
chrome.debugger.sendCommand(debuggee, "Inspector.enable");
});
chrome.debugger.onEvent.addListener((source, method, params) => {
if (source.tabId === target.id) {
if (method === "Network.requestIntercepted") {
// Do many things
} else if (method === "Inspector.detached") {
destroyDebugger();
}
}
})
});
}
I am doing end-to-end testing with protractor. In a certain test, I need to test like print button is creating pdf or not. So When Test clicks the button, It opens the print window dialog like below.
And now this test is not able to be finished. because of this print window. My question is how to close this print dialog in protractor? Because of it, rest of test become pending. Please help. Thanks in advance.
EDIT
I have tried like this..
var printButton=element(by.css('[class="print"]'));
/* This print button should be present first*/
expect(printButton.isPresent()).toBe(true);
browser.actions().mouseMove(printButton).perform();
printButton.click().then(function () {
// fill in the form here
browser.sleep(2000);
// For Pressing Escape key
browser.actions().sendKeys(protractor.Key.ESC).perform();
});
I thought If i got successful to press escape key, then It will resolve the issue.But No Success.
NEXT EDIT--
I have tried new Windows change like below
printButton.click().then(function () {
// fill in the form here
browser.sleep(4000);
browser.getAllWindowHandles().then(function(handles){
browser.switchTo().window(handles[1]).then(function(){
//do your stuff on the pop up window
browser.driver.close();
browser.switchTo().window(handles[0]);
});
});
});
but it shows an error in console and actually It does not open any windows. and hungs up on print dialog as previous.
Failed: unknown error: failed to close window in 20 seconds
EDIT 3
I am having this problem in angular js not in java.
EDIT 4 My Last Attempt
printButton.click().then(function () {
// fill in the form here
return browser.getAllWindowHandles().then(function (handles) {
var newWindowHandle = handles[1]; // this is your new window
return browser.switchTo().window(newWindowHandle).then(function () {
return browser.sleep(5000).then(function () {
return browser.actions().sendKeys(protractor.Key.ESCAPE).perform().then(function () {
return browser.switchTo().window(handles[0])
});
});
});
});
But It does not open a new tab for print Dialog..open print Dialog in same tab.
You need to send the escape to the right window. Also wait for the window to be open before you send it. You probably also need to switch back to handles[0].
return browser.getAllWindowHandles().then(function (handles) {
var newWindowHandle = handles[1]; // this is your new window
return browser.switchTo().window(newWindowHandle).then(function () {
return browser.sleep(5000).then(function () {
return browser.actions().sendKeys(protractor.Key.ESCAPE).perform().then(function () {
return browser.switchTo().window(handles[0])
});
});
});
});
Set the capabilities as below; this will disable the print preview pop up from chrome browser
capabilities: {
'browserName': 'chrome',
chromeOptions: {
args: ['--disable-print-preview','start-maximized']
}
},
I am automating the UI test of my application. There are some cases when i want my test script to close the current browser and and run next test by opening new browser. The problem is that I am unable to figure out how to open new browser window in intern. remote.get(URL) doesn't do what i want to do here. Can someone please help.
I have updated my question to include code as well. My question is pretty much straight forward though. How to open new browser window using intern from inside test ?.
though if you want to see the code please comment, I will write it down .
Thanks.
// in tests/functional/index.js
define([
'intern!object',
'intern/chai!assert',
'Automation/ConfigFiles/dataurl',
'Automation/pages/login/loginpage',
'intern/dojo/node!fs',
'intern/dojo/node!leadfoot/helpers/pollUntil'
], function (registerSuite, assert, dataurl, LoginPage, fs, pollUntil) {
registerSuite(function () {
var loginPage;
var values;
return {
setup: function () {
var data = fs.readFileSync(loginpage, 'utf8');
json = JSON.parse(data);
values = json.values;
loginPage = new LoginPage(this.remote, json.locator);
return this.remote
.get(require.toUrl(json.locator.URL)).setFindTimeout(60000000000).sleep(5000)
},
beforeEach:function() {
// here i want to open new window
},
'valid loginname lands to password page':function () {
loginPage.submitLoginName(values.unamevalue);
loginPage.isPasswordPageDisplayed().then(function(isPasswordPageDisplayed) {
assert.true(isPasswordPageDisplayed, 'password page is not displayed, Invalid Login name');
})
},
'successful login': function () {
loginPage
.login(values.unamevalue, values.pwdvalue)
loginPage.isLoginSuccess().then(function (loginSuccess) {
assert.isTrue(loginSuccess, 'Login Failed');
});
},
afterEach: function () {
return this.remote.closeCurrentWindow()
}
};
});
});
You can open a new window with window.open. The trick is that you want to run that command in the remote browser. Intern (technically Leadfoot) gives you two methods for doing that on this.remote: execute and executeAsync. For example, to simply open a new window, you could do:
this.remote.execute(function () {
window.open();
})
Once you've opened a new window, you need to switch to it to interact with it. A script might look something like:
var windowHandles;
this.remote
.getAllWindowHandles()
.then(function (handles) {
windowHandles = handles;
})
.execute(function () { window.open() })
.sleep(500)
.getAllWindowHandles()
.then(function (handles) {
// compare the new handles to windowHandles to figure out which
// is the new window, then switch to it
return this.remote.switchToWindow(newWindowHandle);
})
.get('some_new_url')
// rest of test
I have a problem when I click in non angular site and the test opens a new non angular site tab. Sometimes works (a lot of times), but sometimes shows the following error:
Unknown Error: null value in entry: name=null
This is the code:
browser.ignoreSynchronization = true;
element(by.id('go')).click().then(function () {
browser.driver.getAllWindowHandles().then(function (handles) {
browser.driver.switchTo().window(handles[1]).then(function () {
browser.wait(EC.visibilityOf(element(by.id('text'))), 15000);
expect(element(by.id('text')).getText()).toEqual('Works');
expect(element(by.css('#crumbsNav .last')).getText()).toEqual('Payment');
});
browser.driver.close();
browser.driver.switchTo().window(handles[0]);
});
How I can fix it?
UnknownError: null value in entry: name=null
Means you are trying to switch to a window that is not opened at the moment.
you should wait for the number of tabs to be more than 1 and only then switch.
So:
browser.ignoreSynchronization = true;
element(by.id('go')).click().then(function () {
browser.driver.getAllWindowHandles().then(function (handles) {
browser.wait(function(){return handles.size() > 1}, 15000);//MY ADDITION
browser.driver.switchTo().window(handles[1]).then(function () {
browser.wait(EC.visibilityOf(element(by.id('text'))), 15000);
expect(element(by.id('text')).getText()).toEqual('Works');
expect(element(by.css('#crumbsNav .last')).getText()).toEqual('Payment');
});
browser.driver.close();
browser.driver.switchTo().window(handles[0]);
});