How to open new tab in browser (in same browser window) with TestCafe? - tabs

I am currently unable to open a new tab in the same browser window. Please refer scenario.
After login, the application opens the page in the same browser
window. I need to click on the card and after it will open in a new
tab and where I need to test everything. Currently, I need to
simulate a direct URL for a new tab but I want to open a new tab with
test case code.
Please let me know is it possible in the test cafe?
Thanks.

Yes, you can pass --disableNewWindow in testcafe/runner argument to open url in same tab.
Also, refer to https://testcafe.io/documentation/402841/guides/advanced-guides/multiple-browser-windows#disable-support-for-multiple-windows
--disable-multiple-windows

Related

Opening a PDF from a link in a new tab

I'm trying to open a PDF file in a new tab (or window depending on the browser config).
Currently if I specify the href for a local file it works as expected, but I need to provide a link that dynamically generated by an API.
So basically:
PDF--> this works (opens the file in a new tab)
PDF--> this opens a new window, closes it immediately and download the file.
I believe this is a security measure by the browser, but is there any way to get around this behavior and show it in a new tab?
You can use JS window.open to open the PDF in a new tab:
<a onclick='window.open("https://the_URL_here.somewhere.some","_blank")'>Open PDF in a new tab</a>
Or call a function that runs the window.open command. Another way would be to generate the link and add it to a layer using getElementById() using the innerHTML property.

How can I make a HTML a href hyperlink open a new window?

This is my code:
test
When you click it, it takes you to Yahoo but it does not open a new window?
test
Easy as that.
Or without JS
test
In order to open a link in a new window, add Javascript command
onclick="window.open('text-link.htm', 'name','width=600,height=400') inside the <a> tag:
Open page in new window
Given answer might be helpful when you want to open a new tab or browser user preference is set to open new window instead of tab, since the original question is about open new window not a tab, here is what works for me.
<a href="#" onClick='window.open(url, "_blank", "resizable=yes, scrollbars=yes, titlebar=yes, width=800, height=600);'>test</a>
Check this one too

window.location.reload refreshing the main window

the following is on a page, when i click it - I DO NOT want the page to refresh, but only the new window which this link opens - i want to refresh that newly opened page, not the main window.
clicking the link opens the new window correctly, but refreshes the main window also (where the link lies). that is undesirable and i want to know how to stop it from doing so.
clik to open new window
clik to open new window
pl advice.
as advised below, but not working: infact it is breaking the new window, new window appears as blank window!
clik to open new window
Here's the proper way to open a link in a new window. If javascript isn't available, the link will still work.
Click Me
mywin is a window name, not a variable.
You need to store the returned wobject from window.open() in a global variable:
onclick="window.mywin = window.open('URL','mywin');">
The problem with the main window reloading is likely the href="" line. This could be causing the browser to navigate to the same page where it is presently (and therefore refreshing). You should add return false; to the js, and likely also adopt a more standard link target like href="#" which will navigate to the top of the same page without a refresh (though this will still get cancelled by the false return).
friends, it is resolved by doing this:
clik to open new window

new tab ID in chrome

I want to know the ID which the original new tab page of chrome would take when I open a new tab?
to inject a javascript code into it.
** note that the new tab I'm talking about here is the original chrome new tab page.
This is not possible, JavaScript injection into Chrome's original New Tab Page is not allowed for security reasons.

How to invoke the same browser instance from a web link

I have a link on my web page. When I click it I open a new window and show content in that window.
I would like to be able, in a second time, to click again in that link and, instead of opening a new browser window/tab, to get the previous instance and put content on it.
Is it possible in some way?
Thanks in advance, greetings.
In HTML you do this by specifying a named target:
Link 2
Link 3
Link 4
All will open in the same window.
Note: If the user has their preferences set to open new windows in tabs, these will all reference the same tab (vs. window)