How to write AppleScript or JXA to click a Safari permission dialog button - automation

I am trying to automate clicking Allow for camera and microphone access in Safari when prompted. I have a TestCafe automated test that runs on Safari and I encounter the following camera and mic permission dialogs once the test starts:
I have Safari Mock Capture devices enabled and would like these mock devices to be active when the test is running.
Here is what I am seeing in the Accessibility Inspector when viewing different Safari browser elements:
I tried to click the Allow button with JXA running in the Script Editor app with no luck:
// Activate Safari, so you will be able to click like a user
Application("Safari").activate()
// Access the Safari process of System Events
var SystemEvents = Application("System Events")
var Safari = SystemEvents.processes["Safari"]
// Call the click command
Safari.windows[1].sheet[0].buttons[0].click()
I get the following error in Script Editor when running the JXA:
app = Application("Safari")
app.activate()
app = Application("System Events")
app.click(app.processes.byName("Safari").windows.at(1).sheet.0.buttons.at(0))
--> Error -1700: Can't convert types.
Result:
Error -1700: Can't convert types.
How can I write AppleScript or JXA that can successfully click on the Allow button for both Safari permissions dialogs?

Related

IE11 Closes when attempting to view source or use F12

We have a set of users who cannot view source or use developer tools in IE11 on Windows 10. right clicking to view source closes the browser with no errors being displayed or found in event viewer. If you hit F12 it will open briefly and then will again close the browser without errors

How does one enable the developer console in Safari for Outlook Add-in Dialog API?

I am working on an add-in that is failing to load scripts via the Dialog API.
The template from the HTML renders correctly in the Dialog. If I render the template in the main TaskPane, both the HTML and the scripts execute correctly.
I can see the console logs in the TaskPane, but the Dialog seems to be a bit of a black box. There's no logs, network, or DOM info that I can see. Is there a way to enable the Safari console for the Dialog?
**** UPDATED: ADDED GIF ****
(the gif slows down the flashing of the screen, but this what happens when attempting to open the inspector in the Dialog)

IE9, Selenium: how to disable download prompting bar ?

I need, for testing purpose, to disable download prompting bar in IE9 (that asks for opening or saving the file), otherwise I cannot test a feature of my app that lets to download a file.
There are download managers that allow to do it, I am wondering where I may put my hands (which Window's registry) in order to remove this download prompting bar.
You can try to switch to new window and close it or execute following code.
driver.switchTo().alert().dismiss();
You don't say which language you are using, but I was able to do this using the following Ruby code.
Note that it does not touch the registry, as asked in your question, but uses the keyboard to interact with the IE9 download bar. It does not disable the download bar altogether, but effectively does the same thing by getting IE to save the file once a download has been invoked.
Selenium can't see the IE9 download bar, so you can't interact with it using Selenium.
require 'win32ole'
#assuming download has started, and IE9 download window is now visible
if $browser = "IE" then
wsh = WIN32OLE.new('Wscript.Shell')
wsh.AppActivate('My webpage - Windows Internet Explorer')
sleep 1
wsh.SendKeys('%s;') # $browser.send_keys #doesn't work - because IE download window is not on the web page.
end

Worklight user-agent

I've been showing a page on the console (Android environment), and testing if this external page (an html page of mine) has been opened using a mobile device or a desktop by checking the user-agent using this piece of code:
navigator.userAgent.match(/Android/i)
If I run this piece of code on the real device it shows it's an Android device, if I launch the Worklight Console it shows it's a desktop device. How can I change the user-agent in order to let Console think it's an Android device? I've installed the Chrome extension but I didn't understand how to use it.
It sounds to me like you want to debug your Android environment (which is meant for mobile devices) while using the Chrome desktop browser?
Try the following and see if this is what you want:
Preview the web resources
If all your web resources are in the common\css or common\js folder, open Worklight Console and click on "preview web resources"
If the web resources are coming from both the common\ and android\ folders, you can use this URL structure: http://replace-with-host-or-ip-address:10080/replace-with-project-name/apps/services/preview/replace-with-app-name/android/1.0,
Open the Chrome DevTools and click on the device icon:
Then, from the UI that will open up you can select from the Devices dropdown to adjust the viewport to that of the chosen Android device.

How do I enable popups in a new Firefox profile using selenium webdriver (Java)

The application I am testing requires pop-up to be enabled. When a launch a new Firefox profile I get the browser message
Firefox prevented this site from opening a pop-up window
with a button on the right called Options. I can manually click the Options button and select to Allow popups from ....
Question is how can I use profile.setPreference to set to allow popups from my website and also not show this Firefox message?
You can save your current Firefox prifile with allowed popups and load it from file like in this case: https://stackoverflow.com/a/6830109/1165331
save you current working profile with popups via browser and loat it.