Karate-UI Automation - How to close Location allowance window (Chrome) - testing

I am using Karate-UI Automation Software. I run my test scenario under Chrome browser. When I go to page where map is displayed (e.g. Mapbox) user is asked about Location allowance (screenshot) with buttons Allow and Deny. Is there some easy trick to confirm/deny/close dialog in scenario step? - in feature file.
location allowance
Thank you for your advice.

Is this the Chrome dialog that does not impact the flow of the test but just stays there and is somewhat irritating ? I'm sorry I haven't found a way to suppress that. Would be great if someone can find a way, I have tried all the flags here, but none of them worked: https://peter.sh/experiments/chromium-command-line-switches/
We are experimenting with Karate-Robot to be able to handle some of these use-cases, but this is still experimental. We need people to try and contribute fixes, if you use this - take 0.9.6.RC1 because 0.9.5 has some issues.
Finally if you are facing a problem with plain HTML, please follow this process so that we can try and figure a solution or enhance the Karate syntax if needed: https://github.com/intuit/karate/tree/develop/examples/ui-test

It works perfectly if you use chromedriver. Refer below code snippet which currently I am using.
Background:
* def session = { capabilities: { alwaysMatch: { browserName: 'chrome', 'goog:chromeOptions': { args: [ '--disable-geolocation', '--test-type' ] } } } }
* configure driver = { type: 'chromedriver', port: 9515, executable: '<Path to chromedriver>', webDriverSession: '#(session)'}

Related

Disable the edge sidebar using Capabilities and EdgeOptions

All I want to know how I can disable edge sidebar using Edge capability.
so i can use it in automation.
I am aware about two different ways to it mentioned below.
Using .send_keys Shift + Ctrl + /
From registry Editor
Open Registry Editor by typing regedit in the Run prompt and pressing the Enter key.
Navigate to the following path:
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Edge
Right-click on the right section, and choose to create a DWORD with the name as HubsSidebarEnabled
Set the value as 0x00000000 to disable it.
But i want to do it using Capabilities and EdgeOptions..
Attaching image of sidebar in edge
Please mention if any solution on this...
Edge version - Version 107.0.1418.62 (Official build) (64-bit)
OS - win10
EdgeOptions, Capabilities
Solution on C#
var options = new EdgeOptions();
options.AddArgument("--disable-features=msHubApps");
Solution on Ruby
DESIRED_CAPABILITIES = {
edge: {
browser_opts: {args: %w( --disable-features=msHubApps),}
}
}
Resource - https://github.com/MicrosoftEdge/EdgeWebDriver/issues/61
I searched a lot including some official documents: Capabilities and EdgeOptions, Browser Options, Capabilities, but didn't find such Capabilities/EdgeOptions.
I think we can't disable Edge sidebar using Edge capability for now. I suggest that you can provide feedback to Edge WebDriver team to help improve the product. Thanks for your understading.
I'll also add that another possibility would be to disable it with prefs.
Java :
Map<String, Object> lPrefs = new HashMap<>();
// Disable Hub Apps Tower
lPrefs.put("browser.show_hub_apps_tower", false);
edgeOptions.setExperimentalOption("prefs", lPrefs);
I find it pretty easy to do like that as I also edit a bunch of other features putting them in my HashMap.
You can find all available preferences using edge://prefs-internals/. Tinkering with this can be very powerful as you can basically find anything that you would need.

Is it possible to make chromium instantly reload on tab crash?

We are running chromium 83 on an embedded system and experience some random tab crashes.
Is it possible to directly reload a tab in chromium, if it crashes (without showing the "Aw snap!" page)?
We're currently trying to patch the source code to get it working and those were our approaches so far.
(both in sad_tab_helper.cc -> SadTabHelper::RenderProcessGone()
Approach 1:
if (SadTab::ShouldShow(status)) {
web_contents()->GetController().Reload(content::ReloadType::NORMAL, true);
}
Approach 2:
if (SadTab::ShouldShow(status)) {
content::RunOrPostTaskOnThread(
FROM_HERE,
content::BrowserThread::ID::UI,
base::BindOnce(
[](content::WebContents* contents) {
contents->GetController().Reload(content::ReloadType::NORMAL, true);
},
std::move(web_contents())));
}
Both changes finally lead to crash of the entire browser.
It seems that chromium tries to reload the page but as said, it then crashes. The log we get are:
[1663:1671:0321/090914.211931:VERBOSE1:network_delegate.cc(32)] NetworkDelegate::NotifyBeforeURLRequest: http://127.0.0.1/login
[1663:1671:0321/090919.082378:ERROR:broker_posix.cc(40)] Recvmsg error: Connection reset by peer (104)
After that the entire browser crashes. Is there a way to do what we want or are we on a dead end here?
The second approach is suboptimal, SadTabHelper::RenderProcessGone only runs on UI.
Initiating navigation while handling notifications from any WebContentsObserver (SadTabHelper is a WebContentsObserver) must be avoided. It leads to problems. The both approaches attempt to do this. I suppose using base::PostTask instead of content::RunOrPostTaskOnThread should help.
if (SadTab::ShouldShow(status)) {
base::PostTask(
FROM_HERE,
{content::BrowserThread::UI},
base::BindOnce(
[](content::WebContents* contents) {
contents->GetController().Reload(content::ReloadType::NORMAL, true);
},
web_contents()));
}
My reputation is not good enough to comment so I can't leave this comment where it should be.
If you come across this particular solution, the required includes are:
#include "base/task_scheduler/post_task.h"
#include "content/public/browser/browser_thread.h"
#include "base/bind.h"

WebdriverIO: Execution context is not available in detached frame

I'm trying to automate a flow that I've been doing at least once a day for the past 3 years. It's an unnecessarily convoluted process that is taking time out of my day. It's an internal proprietary system, so I can't give you any details about it, but suffice to say that I cannot change it. I have to try to automate it the way it is, and I'm stuck with the following error:
Execution context is not available in detached frame "https://..." (are you trying to evaluate?)
I'm using WebdriverIO with the default configuration, which uses Puppeteer internally. When I googled the error, I got a suggestion to add the following flags:
'--disable-web-security', '--disable-features=IsolateOrigins,site-per-process'
I did that, but it didn't help:
remote({
logLevel: 'trace',
capabilities: {
browserName: 'chrome',
'goog:chromeOptions': {
args: ['--disable-web-security', '--disable-features=IsolateOrigins,site-per-process']
}
}
})
I want to try it out in the REPL to do some more debugging, but I haven't figured out how to add those args when launching the REPL:
npx wdio repl chrome
Everything I've tried so far has failed. If someone knows how to do it, please let me know.
I don't do web automation normally and I chose WebdriverIO, since I have used it in the past for mobile automation. I'm wondering if this is a Puppeteer specific issue and if it would work in Selenium, but I'm not quite sure how to set that up. Puppeteer was just working out of the box.
Any guidance on how to get past this error would be greatly appreciated.
Turns out it was pretty simple:
browser.switchToFrame($('#iFrame'))
// Doing stuff inside the frame that causes the next page to show.
// Now that iFrame is gone and I have to switch out of it, to continue:
browser.switchToParentFrame()
// After the above call the execution context is not in a detached frame anymore.

How to configure headless Chromedriver to emulate a device with hover?

In my application, some element should only be present when the device supports hover. Therefore, I use the following CSS:
#media(hover: none) {
#present-only-if-device-supports-hover {
display: none;
}
}
For testing this with Capybara, I’d like to emulate a device with hover. So far I could only get it working in non-headless mode.
I use the following check:
expect(page).to have_selector('#present-only-if-device-supports-hover', visible: true)
With driver :selenium_chrome, the check passes. However, with driver :selenium_chrome_headless, the check fails because the element is not visible.
(As a side note: Capybara::Node::Element#hover works with both drivers.)
I tried a few things which didn’t change this behavior:
I enabled device emulation with options.add_emulation(device_metrics: {width: 800, height: 800, pixelRatio: 1, touch: false}), as it seems like disabling touch enables hover. Indeed, changing :touch to true made it stop working in non-headless mode. But in headless mode, neither works.
I tried to set the webkit.webprefs.available_hover_types and webkit.webprefs.primary_hover_type preferences (which I found during a Chromium code inspection) to 1, but it didn’t have any effect. I also tried leaving off the webkit.webprefs. prefix.
More suggestions?
Try using Selenium-Profiles
It is undetected by companies like cloudfare and google.
For Emulation-settings, have a look at Example-profile

PhantomJS process keeps running in background after calling program.kill()

I'm using phantomjs and webdriverio to fetch and render a webpage that's loaded by javascript, then save it to be parsed later by cheerio.
Here's the code for that:
import phantomjs from 'phantomjs-prebuilt'
const webdriverio = require('webdriverio')
const wdOpts = {
desiredCapabilities: {
browserName: 'phantomjs'
}
}
async parse (parseUrl) {
return phantomjs.run('--webdriver=4444').then(program => {
return webdriverio.remote(wdOpts)
.init()
.url(parseUrl)
.waitForExist('.main-ios', 100000)
.pause(5000)
.getHTML('html', true)
.then((html) => {
program.kill()
return html
})
})
}
Even though I call program.kill() I notice that the phantomjs in the list of processes, and it does use up quite a bit of RAM and CPU.
I'm wondering why the process doesn't terminate.
.close() just closes the window. There is a known bug, if it is the last window it stays open.
.quit() should do it, but there are issues associated with that as well.
PhantomJS bug report: https://github.com/detro/ghostdriver/issues/162
someone has a decent workaround posted at the bottom of that thread:
https://github.com/SeleniumHQ/selenium/issues/767#issuecomment-140367536
this fix shoots a SIGTERM to end it: (In python, but might be usefull)
# assume browser = webdriver.PhantomJS()
browser.service.process.send_signal(signal.SIGTERM)
browser.quit()
I like to just open a Docker container with my automation, and run it in there. Docker closes it up for me, however that is prolly out of scope for what you want to do.. i would recommend the above SIGTERM+quit method.
PhantomJS is a 2 component product. There is the Javascript which runs on the client (Whether web or other Script) side as part of your code. Then there is the part that runs as a server-side application (The command line call)
It has been my experience with PhantomJS that when an error is encountered, the PHantomJS server side "hangs" but is unresponsive. If you can update your call to this script to provide output logging, you may b able to see what the error is that PhantomJS application is encountering.
phantomjs /path/to/script/ > /path/to/log/file 2>&1
Hope this Helps! If you'd like me to clarify anything, or elaborate I'm happy to update my answer, just let me know in a comment, Thanks!