Nightmare JS will not open file dialog - dialog

If I click the button manually, or if I run .click() in the console, the open file dialog pops up in the Electron browser, and works fine.
However if I run it automatically by nightmare, the window pop up does not appear.
I have tried clicking in within evaluate, giving the element an id, to be sure I am interacting with the element, and then clicking the ID with nightmare
var clickUpload = await nightmare.evaluate(function (selector) {
document.querySelector(selector).id="theElement";
return "Element Given ID";
}, ".camera")
await nightmare.wait(2000);
nightmare.upload("#theElement","./pic.jpeg")
nightmare.click("#theElement")

Related

Chrome Extension - Find out if extension tab is open

I have set up that when I click extn icon - my extn index.html opens.
If I click the icon a second time - I don't want it to open a second tab; I want it to focus the already open tab (if it's open).
The problem is with if it's open part. Ideally, I would not want to ask for a tabs permission, as it is very intrusive. Because of this restriction I cannot iterate all the open tabs and check their urls.
I tried storing extn tab id in chrome.local.storage and checking for it when I click the extn button - but always maintaining up-to-date tab number proved to be rather difficult. The ultimate obstacle was that when Chrome is closed - it doesnt fire any type of onClose event; thus I cannot clear local storage of now obsolete extn tab id.
So, when I reopen Chrome, click extn button - it will not open the new tab because it can see the old tab id in the storage and thinks that a tab is already open.
Is there any way to achieve the result w\o the tabs permission?
For embedded options shown in chrome://extensions UI you can simply use chrome.runtime.openOptionsPage() which will take care of refocusing the existing tab.
To find a standalone tab of your own extension use chrome.extension.getViews() and chrome.tabs.getCurrent() invoked on the other tab's JS window to get its own "current" tab:
function getOwnTabs() {
return Promise.all(
chrome.extension.getViews({type: 'tab'})
.map(view =>
new Promise(resolve =>
view.chrome.tabs.getCurrent(tab =>
resolve(Object.assign(tab, {url: view.location.href}))))));
}
async function openOptions(url) {
const ownTabs = await getOwnTabs();
const tab = ownTabs.find(tab => tab.url.includes(url));
if (tab) {
chrome.tabs.update(tab.id, {active: true});
} else {
chrome.tabs.create({url});
}
}
Usage:
openOptions('index.html')

Why am I getting the previous tabs url?

I am trying to get the url of the window that is opened by clicking the element with id 'wrpr_1431108056877h'. The new window opens but getTitle() still returns the title of the original tab. On the video provided by Browserstack I am able to verify that the current tab is indeed the one that I am trying to access.
browser
.click('#wrpr_1431108056877h')
.pause(5000)
.getTitle()
.then((url: any) => {
console.log(url);
})
.end()
.catch((err: any) => {
console.log(err.message);
done(Error('Could not move'));
});
browser.getTabIds();
should give you a list of all the window handles that webdriver knows about.
then you can use
browser.getCurrentTabId();
to figure out which window is currently in focus (Maybe this is what you said you are doing from the BrowserStack video?)
My guess is that the newly opened window isn't the currently focused window. Hence any commands executed (like getTitle()) will happen on the previous window.
You can switch the focused window to the newly opened window by calling
browser.switchTab(windowHandle)
Then you can call getTitle() and it should return the correct title.
See the web driver docs on Window here: http://webdriver.io/api/window/getTabIds.html
(scroll all the down on the left hand side to see the complete Window section)
for more info.
Please call
browser.navigate().refresh()
Before calling
browser.gettitle().

How To Navigate From Parent Window To Popup Window using Node js Night Watch

I am implementing facebook login automation on my site using night watch.I am successfully able to opening facebook login window in popup but can't able to access popup window using night watch
please help me
I've been using the following in my tests. You need to explicitly change focus to the pop up window in your script.
.window_handles(function(result) { // Since two windows are open we need to get the window ids
var temp = result.value[1]; //
this.switchWindow(temp); // and switch focus to the new window so that the next command is run against it
}) //
to switch focus back to the the original window you can use the following
.window_handles(function(result) { // Since two windows are open we need to get the window ids
var temp = result.value[0]; //
this.switchWindow(temp); // and switch focus to the new window so that the next command is run against it
}) //

what is the use of window.open('','_self').close(); in chrome extension

When I click the extension icon, a popup is shown.
After that, when I try to click "URL restrictions", it will open a window, after that when I click the popup again, the popup is overlapping that url restriction window.
The above issue happens on Windows only, not on Linux.
So I have added window.open('','_self').close(); which apparently fixed the issue. But not exactly. Is it correct? I have referred this Link and Link2 but can not understand the meaning.
What is the purpose of window.open('','_self').close();?
EDIT: this is my popup.js
function click(e) {
var windowObj = window.open(site_exception_url, 'url_window', params);
windowObj.focus();
window.close();
window.open('','_self').close();
return false;
}
On Windows the popup isn't closed automatically after a new window is opened from a link within the popup.
Close it in the click handler manually, this won't hurt Linux but will help on Windows:
document.addEventListener("click", function(event) {
if (event.target.localName == "a") {
close();
}
});
The related questions linked in your question don't apply here as the first is for userscripts, not extensions, and the second isn't for popups shown by the browser when you click the toolbar button.

How can I make fiddles enter full-screen?

I was trying to create some POC to try something with jwplayer but for some reason full screen for jwplayer is not working.
Is there any way to make full-screen work in jsfiddle in jwplayer?
Here is my jsfiddle
http://jsfiddle.net/hiteshbhilai2010/6YyXH/63/
Answering too late, but as no share button is available now, the new way for going full screen is copying the URL of your fiddle and append /show to it.
Example : https://fiddle.net/xyz123/show/
This will show you only the result frame in full screen.
You can click on Share button, then take the Full screen result URL, open it, go to full screen in player and then (optionally) click on F11
Another quick way: right click on jsfiddle result --> View frame source --> In the view source tab take the iframe URL and open it, the player full screen should work. If you are intending to use the fiddle as a demonstration, you can write some javascript to grab the url of the underlying iframe and open it in a new window.
In firefox only:
Right-Click the result window in Jsfiddle
Select "This Frame"
Select "Show Only This Frame"
Page will reload with result only in full screen (without a "run this fiddle" banner in it.)
Sometimes however this won't work, I not shure why, but you can always add "/show" to the URL as Zameer Fouzan has said.
If you don't want to see the "Edit in Jsfiddle" button you can always remove it:
Add "/show" to the URL and press ENTER
Press "run this fiddle" button
Press F12 to enter developer mode in FireFox or Chrome
In firefox press: CTRL + SHIFT + C to pick an element from the page
Press the "Edit in Jsfiddle" button, the corresponding code will be highlighted
Right-Click the highlighted line of code
Select "Delete Node"
Press F12 to close developer mode
Open your browser's console and run this:
const div = document.createElement('div')
div.classList.add('actionItem', 'visible')
div.style.cursor = 'pointer'
const a = document.createElement('a')
a.innerText = 'Fullscreen'
a.classList.add('aiButton')
a.title = 'Fullscreen'
a.addEventListener('click', function() {
document.querySelector('iframe[name=result]').requestFullscreen()
})
div.appendChild(a)
document.querySelector('.actionCont').insertBefore(div, document.getElementById('app-updates'))
This will add a button with the text "Fullscreen" next to the "Embed" button. If you click on it, your browser should fullscreen the result.
Or, if you don't want to paste something in the browser console every time you go to edit a fiddle, use a userscript:
// ==UserScript==
// #name JSFiddle Fullscreen
// #match *://jsfiddle.net/*
// #version 1.0
// #author GalaxyCat105
// #description Adds a fullscreen button in the JSFiddle navigation menu when editing a fiddle
// #grant none
// ==/UserScript==
const div = document.createElement('div')
div.classList.add('actionItem', 'visible')
div.style.cursor = 'pointer'
const a = document.createElement('a')
a.innerText = 'Fullscreen'
a.classList.add('aiButton')
a.title = 'Fullscreen'
a.addEventListener('click', function() {
document.querySelector('iframe[name=result]').requestFullscreen()
})
div.appendChild(a)
document.querySelector('.actionCont').insertBefore(div, document.getElementById('app-updates'))
Create a new script in your favorite userscript manager and copy-paste the code into it.

Resources