Set localStorage and read upon app startup in selenium - selenium

It is a selenium - webdriver - chromedriver e2e test what would test a multi-platform angular application with ionic, using capacitorStorage.
I would like to set a value in localStorage to skip an onboarding flow for test cases which does not contain onboarding related assertions.
I'm running the e2e test on an emulated android phone.
await webView.switchToContext(CONTEXT_REF.WEBVIEW);
await browser.execute((keyName, keyValue) => {
localStorage.setItem(keyName, keyValue);
}, "CapacitorStorage.settings/onboarding-done", "true");
The value is set, but the application reads out the value already by the time, the localstorage.setItem call runs.
I tried using driver.closeApp(); await driver.background(1); await driver.launchApp(); but the launchApp starts a new session with clear storage.
My idea would be to setup the localStorage before the app reads it, or restart the app after the localstorage values has been set without a reset.

Related

FusionAuth oAuth not working with TestCafe

I am failing to correctly login through the UI with the testing framework TestCafe. Our company uses FusionAuth for authentication which lives on a separate Domain from the application I am looking to test. At the moment im just trying to develop a Proof of Concept with logging in through the UI.
Currently, the cookie that I often see get set when logging in normal through my browser does not get set when going through testcafe. Thus when you return to the application it does not to know that you are authenticated.
It seems that the passing of cookies / local storage from the IDP login page back to the Application in test does not happen.
Ive tried useing Role's with preserveUrl set to true.
const testUser = Role('{domainURL}/login', async t => {
const username = 'username'; //Not real values
const password = 'passwword';
await t
.typeText('#loginId', username)
.typeText('#password', password)
.click('.submit');
}, { preserveUrl: true });
test
.disablePageCaching('Login to Test Users Account', async t => {
await t.useRole(testUser);
});
Ive also tried just using selectors and putting in the Credientials manually in the UI. Neither have worked so far for me.
I was curious if:
I am approaching this wrong?
What is the best approach for Black box End-2-End Testing with testcafe when dealing with login?
I know this is probably not the best place, but i wasn't sure how else to contact testcafe support.
In general, TestCafe Roles is the recommended approach for dealing with logging. There can be some FusionAuth specifics that do not work correctly with TestCafe. If you want our TestCafe team to research this issue, you can create an issue in our github repository using the following link: https://github.com/DevExpress/testcafe/issues/new?assignees=&labels=&template=bug-report.md
Please note that we will need an example that demonstrates the issue. If you cannot share your project/login/password publicly, you can send it to support#devexpress.com.
This was turned into a github Issue ticket that can be found here. Going to close this Question for now.

onAuthRequired triggering only once in Chrome version > 72

In our project we are using Selenium to test our Angular Web Application using a docker image and chrome with version 70.0.3538.77 (Official Build) (64-bit). Since the application uses basic authentication on our servers we created our own extension to listen to "onAuthRequired" and whenever this happens we return the username and password (Original Source).
A simple test for our application would be to navigate to the main page (basic auth login required with the popup window) and then to another subpage that is hosted inside of this page in an iframe where the basic authentication is required again.
We added some logging to the extension just to check whether the onAuthRequired gets triggered so the extension currently looks like this:
​if (!chrome.webRequest.onAuthRequired.hasListener(retrieveCredentials)) {
chrome.webRequest.onAuthRequired.addListener(
retrieveCredentials,
{urls: ["<all_urls>"]},
['blocking']
);
}
function retrieveCredentials(details) {
console.log("onAuthRequired");
return {
authCredentials: {
username: username,
password: password
}
};
}
What we found out is that with the Version 72.0.3626 this was still working. The extension would fill out both of the login prompts that occur and we would see two messages with "onAuthRequired" in the console.
However with the Version 73.0.3683 and newer, this seems to not work anymore. Only one time the onAuthRequired (retrieveCredentials-Method) is called and the second popup gets ignored by the extension. This lets the Selenium tests fail with a timeout exception since the navigation doesn't work anymore.
Does anyone know how to handle this in the newer Versions of Chrome or sees a mistake that we made in our extension?
Any help appreciated

Puppeteer on an express.js server cookies

I'm running puppeteer on an express.js server. Some of the webpages I go to require puppeteer to login. I'm using
const browser = await puppeteer.launch({
userDataDir: "./user_data/",
});
to store the session cookies so that I don't have to login each time, however, whenever I restart the express.js server the cookies seem to disappear and I'm required to login again.
Why does this keep happening? And is there a way to stop it from happening?
Hmm, I can't say I know exactly what's causing your issue, but I also experienced a number of difficulties getting puppeteer to properly save all session data (building bots to login to bank accounts to check balances, etc.) To remedy this I created some helper functions that use zlib to pack up the cookies (both from the direct Chrome Dev Tools client command, and the puppeteer API) along with the entire user data directory as a base64 string.
Here's a gist I created that you can run. You will need to decide where to store the base64 string containing the session data, but once done, you can import it into any puppeteer instance using the appropriate function and replicate the exact browser state. In my case, I am using firestore but obviously any storage solution will do.

Vue.js PWA, vuex: 'An unknown error occured when fetching the script'

I have the following setup:
Vue PWA starter
Vuex store
Persist plugin to have data available offline
The sw registers properly and also loads the cached files containing my vue app when offline. The problem: The data that's stored in the localStorage doesn't show up, although it is available in the localStorage.
In Chrome's Application tab I see the error An unknown error occured when fetching the script. There's no assigned line of code from the worker or anything else.
So right now I don't know whether the problem is my worker, the plugin or something else. Are there any good approaches to tackle such 'magic' problems?
BTW: I left the service worker as is from the Vue PWA starter.
Store initialisation if it helps:
const localStorageConfig = new VuexPersistence({
key: 'someAppCode',
});
export default new Vuex.Store({
modules: {
user,
client,
tours,
},
plugins: [localStorageConfig.plugin],
});

How to stop selenium webdriver from closing the browser?

Normaly you are using selenium to automate testcases and after the testcase finished running, the browser closes.
However I try to use selenium webdriver to script specific tasks, e.g. login to a specific page but the browser should stay open after it.
I need the browser to stay open, because I developed a CMS where you can define selenium tasks and execute them. One of the tasks is to login to a backend, but I need to keep the website open forever, so that I can work in the backend. Problem: after about 20 minutes or so the browser which opened by starting the testcase, closes again.
I developed the portal so that I don't have to login to all my backends if I start working at the morning, I only have to login once into my portal and from there I can trigger everything I need.
I do it like this to login to typo3 backend (snippet):
$username_field = $SeleniumObj->byId('t3-username', true);
$pw_field = $SeleniumObj->byId('t3-password', true);
$submitButton = $SeleniumObj->byId('t3-login-submit', true);
$username_field->sendKeys("myusername");
$pw_field->sendKeys("mypasswd");
$submitButton->click();
exit;
You can see that I call exit at the end so that the "testcase" ends and the page stays open.
How to set the browser lifetime to infinite?
NOTES: I am using the latest selenium and facebook php-webdriver with custom code wrappers.
Testcase is to login to specific page.So, after using login credentials once login to specific page successfully, then testcase ends there.
Remove exit & see.