How to make WebdriverIO switchWindow to work with Firefox - firefox

I'm learning to use webdriverio, and the tutorial's example for multiple tab switching works just fine with chrome and safari, but not in firefox (v106).
this is the code:
describe('Manage multiple windows', function () {
it('should switch to another tab', async () => {
await browser.url('http://the-internet.herokuapp.com/windows')
await (await $('.example a')).click()
await browser.switchWindow('http://the-internet.herokuapp.com/windows/new')
await expect(browser).toHaveTitle('New Window')
})
})
The error I get in the log is this:
[firefox 106.0.1 mac #0-0] No window found with title, url or name matching "http://the-internet.herokuapp.com/windows/new"
[firefox 106.0.1 mac #0-0] Error: No window found with title, url or name matching "http://the-internet.herokuapp.com/windows/new"
[firefox 106.0.1 mac #0-0] at processTicksAndRejections (node:internal/process/task_queues:96:5)
[firefox 106.0.1 mac #0-0] at async Context.<anonymous> (/Users/roni/code/tau/wdio7-tutorial/test/specs/switchWindow.test.js:7:9)
I tried looking for answers but could not find much that relates to this specific issue.
Found this on the webdriverio github, but I don't think it's the same problem: https://github.com/webdriverio/webdriverio/issues/7619
Is this a webdriver, a Mac or a firefox issue?
Is there a workaround?

Related

Accessing background page for firefox add-on in puppeteer

Is it possible to get background_page target for Firefox Add-on in puppeteer?
For testing chrome extensions, I can easily access the background_page when extension is loaded by doing the following:
// Bring up chrome browser with extension loaded
const browser = await puppeteer.launch({
headless: false,
defaultViewport: null,
ignoreHTTPSErrors: true,
timeout: 0,
args: [
`--disable-extensions-except=${CRX_PATH}`,
`--load-extension=${CRX_PATH}`,
'--ignore-certificate-errors',
'--no-sandbox',
'--disable-setuid-sandbox',
'--window-size=1920,1080',
],
});
// Fetch browser targets
const targets = await browser.targets();
// Filter out background_page for extension from the targets
const backgroundPageTarget = targets.find((target) => {
return target.type() === 'background_page';
});
I was able to load my firefox add-on by following these guides:
https://github.com/puppeteer/puppeteer/issues/4162
https://github.com/puppeteer/puppeteer/blob/f26bb7f4c44d9b7db5cc73c4af32db6fa5bcd3a2/experimental/puppeteer-firefox/README.md#add-ons
However, I've been unable to access the background_page of the add-on. I need that to intercept and validate requests and responses made by the add-on.
I managed to make it work with Selenium by following these steps:
Open up the same Firefox browser application that you're making Puppeteer connect to.
Load the extension the same way that you make Puppeteer load it (there's different ways, I did it by loading an unsigned version with Firefox dev edition).
Activate the popup window for the extension, then right click and select View page source.
In the URL, you should see this pattern view-source:moz-extension://<extension-id>/<extension-page-name>.html
Using this extension ID, you can make your script go to the background page by having the browser navigate to moz-extension://<extension-id>/<background-page-name>.html

Protractor - How to submit a form in firefox (works ok in chrome)

In Chrome
input.sendKeys('123\n');
submits the form and sends me to the result page, as does
input.sendKeys('123');
input.sendKeys(protractor.Key.ENTER); // or .RETURN
but in firefox, neither approach work, I can't seem to get enter to work that way and so I stay on the same (original) page and the test fails.
I keep getting (Firefox only):
Failed: Element <input class="gNO89b" name="btnK" type="submit"> could not be scrolled into view
I've also tried:
browser.actions().sendKeys(protractor.Key.ENTER).perform(); //invalid (older?) syntax.
also
input.sendKeys(protractor.Key.TAB);
input.sendKeys(protractor.Key.TAB);
input.sendKeys(protractor.Key.ENTER);
also, suing the submit button on the page
$('input[value="Google Search"]').click();
also
$('input[name="btnK"]').click();
also
input.sendKeys('123');
input.sendKeys(protractor.Key.TAB);
$('input[value="Google Search"][name="btnK"]').click();
They mostly work in chrome, just not in firefox, or at worst, in neither.
The failure (showing I am still on the original page) is
[firefox #01] Failures:
[firefox #01] 1) Google search field should have a result page
[firefox #01] Message:
[firefox #01] Expected 'About Store
[firefox #01] Gmail
[firefox #01] Images
[firefox #01] Sign in
[firefox #01] PrivacyTermsSettings
[firefox #01] AdvertisingBusiness How Search works' to contain '123'.
[firefox #01] Stack:
[firefox #01] Error: Failed expectation
The chrome tests pass and the other (10) firefox tests pass ok and bring up the firefox browser and use the browser ok but they don't try to submit the form as this one does.
Note: I tried adding --safe-mode and --headless but they didn't help.
I tried surrounding calls with browser.sleep(2000)s but that didn't help.
I tried using
input.sendKeys(protractor.Key.TAB);
browser.sleep(1000).then(function() {
$$('input[value="Google Search"].first').click();
});
browser.sleep(2000).then(function() {
expect($('body').getText()).toContain('123');
});
but that didn't help

Alert is not visible in nativescript ios after autocomplete usage

I am working on a nativescript app for android and ios in which I have used REST APIs to store/get data in JSON format.
Based on JSON result from APIs sometime I need to show alert to the user.
It was working fine with Nativescript 4.1 but since I have upgraded to 4.2 app is unable to show alert boxs in ios. It shows the blank page and shows the following error.
(UIKitCore) Warning: Attempt to present <UIAlertController: 0x7fb5834eb000> on <UIViewControllerImpl: 0x7fb58659a670> whose view is not in the window hierarchy!
I have suspected that I am calling alert too early so I have tried to add timeout before alert but still it's the same.
if (result.status === 'E') {
setTimeout(function () {
const alertOptions = { title: 'Error', message: result.errMsg, okButtonText: 'OK', cancelable: false };
dialogs.alert(alertOptions).then(() => {
resolve('Error');
});
}, 700);
Points to note here is I am using nativescript-autocomplete component in one of my tabs. and this problem occurs only when user searches something using that component.
So it could be something related to that component.May be when autocomplete closes the modal, app looses the parent reference ?
Found an interim solution for now.
nativescript-fancyalert works like a charm. Will stick with that for sometime.
It is based on SCLAlertView for ios.

Puppeteer open page hangs with elevated console

Recently working on crawler project.
I noticed when I run the script under adminstrator (elevated console in Windows), the chromium will hangs with a sad face tab... no errors will report until I Ctrl+C to halt the script.
But with no code changes and I run the same script under normal non elevated console, everything works out just fine...
Was wondering if anyone met this issue before ?
Thank you very much for your time.
const browser = await puppeteer.launch({ headless: isHeadless });
const page = await browser.newPage();
var error = undefined;
await page.goto(landingURL,{ waitLoad: true, waitNetworkIdle: true });
await page.addScriptTag({ url: jquerySource });

Screenshot on a react page is blank using casperjs

I am trying to use casperjs on a react app and noticed that screenshots were coming back as blank. So, I tried a different app and got the same result.
So, here is a react app I found - http://jaredly.github.io/github-issues-viewer/#rails/rails/0 and here is the casperjs code
var casper = require('casper').create();
casper.start('http://jaredly.github.io/github-issues-viewer/#rails/rails/0', function() {
this.echo(this.getTitle());
this.capture('im.png')
});
The image shows blank info
How do I resolve this?

Resources