How to allow Safari camera and microphone permissions in a TestCafe test - testing

I would like to click 'Allow' on the camera and microphone permission dialogs that show up in my TestCafe test. How can I handle these dialogs in TestCafe to click Allow?
First Safari camera permission dialog
Second Safari camera and microphone permission dialog
I've tried the following solution in my test to click the Allow button but it didn't work and the dialog remains:
await t
.setNativeDialogHandler(() => true)
.click(Selector('button').withText('Allow'));
Alternatively, is there a way to programmatically configure Safari's camera and microphone permissions to Allow? I am running the automated test on Sauce Labs and would like the camera and microphone permissions to be Allowed so I can use Safari's mock capture devices during the test.
For example, I can enable Safari's mock capture devices programmatically on Sauce Labs by executing the following commands under the preExec sauce configuration in .sauce/config.yml:
- name: "Safari in sauce"
platformName: "macOS 12"
browserName: "safari"
mode: sauce
preExec:
- /usr/libexec/PlistBuddy -c 'Add :WebKitMockCaptureDevicesEnabled bool 1' ~/Library/Containers/com.apple.Safari/Data/Library/Preferences/com.apple.Safari.plist
- /usr/libexec/PlistBuddy -c 'Add :WebKitPreferences.mockCaptureDevicesEnabled bool 1' ~/Library/Containers/com.apple.Safari/Data/Library/Preferences/com.apple.Safari.plist
- /usr/libexec/PlistBuddy -c 'Add :WebKitPreferences.mediaCaptureRequiresSecureConnection bool 0' ~/Library/Containers/com.apple.Safari/Data/Library/Preferences/com.apple.Safari.plist
- /usr/libexec/PlistBuddy -c 'Add :WebKitMediaCaptureRequiresSecureConnection bool 0' ~/Library/Containers/com.apple.Safari/Data/Library/Preferences/com.apple.Safari.plist
Is there a way I can do similar configurations for the camera and microphone permissions in Safari?

Alternatively, is there a way to programmatically configure Safari's camera and microphone permissions to Allow?
The setNativeDialoagHandler method is not intended for handling the Camera Permission dialog. Try to execute each instruction from the preExec section programmatically using the exec method before the test run.

Related

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

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?

Robot Framework - Chrome forces me to choose the profile

I'm facing an issue when I try to open the browser with RobotFramework in chrome. For some reason chrome forces me to choose the profile. I've tried to add arguments to the options parameter in Open Browser command which indicates the desired profile but for some reason it ends with the same pop-up window again.
Open Browser ${FINESSE_URL} ${BROWSER} options=add_argument("--ignore-certificate-errors");add_argument("--disable-notifications");add_argument("--disable-logging");add_argument("--profile-directory=Default");add_argument("--user-data-dir\=C:/Users/pc/AppData/Local/Google/Chrome/User Data");
choose profile screenshot

Dismiss Authentication popup while running selenium tests in Headless mode from Jenkins (with Linux Agents)

How to dismiss authentication popup while running selenium tests in headless mode through Jenkins ? My tests run in Linux docker containers in Jenkins Environment.
The application has SSO enabled hence in most cases, I don't get this popup unless I open the application in incognito mode or run tests through Jenkins (where SSO doesn't work), in which case I just have to dismiss it (same as clicking on cancel button on the popup or pressing ESC key). Also note, entering credentials in the popup won't work (will not launch the application, instead gives error, could be due to oAuth/SSO).
I'm already aware of the following approaches, but none of them really work -
Passing credentials in URL - This approach won't work as it is not basic authentication.
AutoIT - works only in windows OS
Robot class (to press ESC key) won't work in headless mode.
How can I dismiss the authentication popup in headless mode ? I read about Wine tool as AutoIt alternative for Linux OS. Is that the only way to handle this scenario?

How to get Selenium Webdriver to run on Firefox browser as a different user?

I want to open an application website on Firefox browser using Selenium Webdriver as a different user.
Currently, I am using gecko driver to open that application link, it successfully opens up the browser but unable to open the application link.
But I am able to achieve the same manually by going to Mozilla Firefox icon and clicking on
"Run as different user"
option (as shown in below image) which further open a popup for user credentials and by entering Username and Password of different user there I am able to open the application link in browser.
So, is there any way that I can achieve same process using Selenium Webdriver and opens up my application link.
Thanks in Advance!!
You should rather create Firefox profile by running firefox.exe -p to launch profile manager. Then you can instantiate firefox web driver implementation and configure it to use given profile.
Are you sure that you want to use pre-configured profile? I find much easier to manage to run drivers in private/incognito mode and set cookies manually to configure tests.
You might provide firefox_binary as a parameter for the webdriver:
http://selenium-python.readthedocs.io/api.html
firefox_binary – Instance of FirefoxBinary or full path to the Firefox
binary. If undefined, the system default Firefox installation will be used.
...so, you might use a wrapper script to run firefox as the different user (use sudo in Linux).

cancel Windows authentication prompt on chrome through selenium

I'm trying to write a selenium test which :
Connect to a website (which prompt an authentication window)
Click on "cancel" of the authentication window
Do some test stuffs...
But my problem is that : I am not able to cancel the authentication step.
My test should not depend on the environment (I don't want to change the Windows registry keys)
I found this chromium command "--auth-server-whitelist=..." that automatically fills and submit this prompt and I am looking for something that would always refuse the authentication.
Any Ideas ? Suggestions of better ways ?