Closed alessandrostassano closed 1 year ago
Can you share the contents of the openPacketDetails
function?
If removing target="_blank"
doesn't work, my best guess is that openPacketDetails
calls window.open() to open the page in a new tab. In that case, you should be able to patch window.open()
to stop it from being called with a _blank
target argument.
// after visit, but before click
cy.window().then((win) => {
const orig = win.open
win.open = function (url, target, features) {
return orig.call(this, url, '_self', features)
}
})
// click the link
Can you share the contents of the
openPacketDetails
function?If removing
target="_blank"
doesn't work, my best guess is thatopenPacketDetails
calls window.open() to open the page in a new tab. In that case, you should be able to patchwindow.open()
to stop it from being called with a_blank
target argument.// after visit, but before click cy.window().then((win) => { const orig = win.open win.open = function (url, target, features) { return orig.call(this, url, '_self', features) } }) // click the link
Hi, This is the content of the function. I'm not sure what i have to do: the parameters indicated have to be customized?
As I suspected, the function uses window.open()
. Can you try putting the following code before the relevant click()
in your test and see if it fixes the issue?
cy.window().then((win) => {
const orig = win.open
win.open = function (url, target, features) {
return orig.call(this, url, '_self', features)
}
})
As I suspected, the function uses
window.open()
. Can you try putting the following code before the relevantclick()
in your test and see if it fixes the issue?cy.window().then((win) => { const orig = win.open win.open = function (url, target, features) { return orig.call(this, url, '_self', features) } })
It works, thanks a lot!!! What a great workaround!! So grateful
@chrisbreiding Hey chris, I am stuck at same problem since 3 days, can you help me, I tried above code but that didn't work for me
Here is my development code, in which they using window.open
Here is what i tried in cypress
@chrisbreiding please look into my problem, this is very important me to handle this. Thanks in advance
@mohd-faisel please open a new issue with a reproducible example and the Cypress team will be happy to investigate. I also want to level set that open source issues have no guarantee around when and even if we will be able to solve them.
If you are looking for other ways to get help using Cypress check out our community chat, it can be helpful for debugging or answering questions on how to use Cypress.
Current behavior
When i click a specific button to continue the navigation in our booking application, i use the ".invoke(remove attribute target)" function to denied to the button the possibility to open a new chrome tab. This solution doesn't work because the properties that open new tab is contained in a javascript function, despite the target:blank properties is correctly contained in html element. I put the screen of the chrome dev tools. Is there an alternative workaround to fix this behavior and switch off a javascript function contained the target blank?
Desired behavior
Switch off the blank properties and stay in the current chrome page.
Test code to reproduce
cy.xpath(e_PlpPageElements.PrimoBottoneProsegui).invoke("removeAttr","target").click()
In "e_PlpPageElements.PrimoBottoneProsegui" is contained the xpath of the button "Prosegui" that i have to click.
The properties of Prosegui are these:
I switch off target, but it doesnt work. I have to switch off ng-click="openPacketDetails(hotel, ''). Is there a workaround?
Cypress Version
11.0.1
Node version
16.17.0
Operating System
Windows 10
Debug Logs
No response
Other
I attached the screen. The button "prosegui" has these properties, but the function _blank is contained in ng-click=""openPacketDetails"