TestCafe window.sessionStorage.getItem() returns null - testing

Our application use browser session storage to store information which will be read by child window.
There is example scenario:
User clicks on link to open child window. New window is opened with window.open() and then we store information in child's session storage. When child window is loaded it will get information from session storage.
Problem:
When child window trying get value from session storage (with: window.sessionStorage.getItem('my_key')) it returns null and because of this application doesn't work properly when run in TestCafe and tests are failing.
In chrome dev tools I can see that session storage has this value. I printed to console what is under window.sessionStorage and it returns Proxy object (see screenshot):
I checked and key provided to window.sessionStorage.getItem is correct and also I noticed that under 'internal -> nativeStorage' is my value that I'm looking for (is not visible on screenshot because I can't show this data).
I don't know if it is a bug or I just need configure something but I didn't find information about it in google.
Is it possible to make TestCafe works as expected in this scenario? If yes, how?

It happens because TestCafe can't open a page in a new tab in the same window and opening a page in a new window creates a new session Storage. To work around this you can use disableMultipleWindows.

Related

Is it possible and if so how to clear localStorage with RobotFramework?

I've seen doc's for robotframework and i do not see posibility to clear local storage.
Basically I want to have test that sets some coockies with Switch To methodes.
Test Button Visibility For Administrator
Switch To Administrator
Go To Page ${VIEW}
Wait Until Page Contains ${BUTTON}
Test Button Visibility for User
Switch To User
Go To Page ${VIEW}
Wait Until Page Does Not Contain ${BUTTON}
There isn't a Selenium/SeleniumLibrary method for doing that (yet?), but localStorage is manipulated through JS. Here's a call to remove a specific key in it:
Execute Javascript window.localStorage.removeItem('your_key_name');
You can use the Execute JavaScript command to clear the localStorage, which basically will run the command in the browser console:
Execute JavaScript localStorage.clear();
More options here: https://www.w3schools.com/jsref/met_storage_clear.asp

Selenium : After clicking a Click in home page , one more screen appears and it got altogether different new DOM loaded

Selenium : After clicking a Click in home page , one more screen appears and it got altogether different new DOM loaded and am currently unable to handle any elements using selenium and getting Element not found exception
Note : Tried Manually to load the same page and in browser console provided the same element and got nothing . but after long time it shows element. Is there a way to handle it?
You can handle your child window using below code. Basically we need to switch web driver control from your parent window to child window and once you finish process then again you have to switch control back to your parent window for further process. We can use window_handles to get handle of all opened windows by web driver and then we can switch from one window to another in a web application
Different Windows
Python :
driver.switch_to_window(driver.window_handles[-1])
title=driver.title
To handle synchronisation issue you can always use different types of waits available in the selenium e.g: implicit, explicit etc.

Unable to successfully call captureVisibleTab() despite requesting <all_urls> permissions

I'm working on a browser extension for React DOM. This extension has a "Profiler" UI which measures render performance for React components. I recently added screen captures to this Profiler so that it can show images of the DOM each time React updates it.
To do this, the extension calls chrome.tabs.captureVisibleTab in response to a request from the DevTools extension UI. (This request is made each time React commits changes to the DOM.)
I've required the <all_urls> permission for now, based on the documentation for this API, which says:
You must have the <all_urls> permission to use this method. (Alternately, Chrome allows use of this method with the activeTab permission and a qualifying user gesture).
(The Chrome documentation for this API doesn't mention either way.)
In my experience, I am able to capture the screen after updates caused by e.g. clicking on an anchor element. However, other types of updates (e.g. "scroll" events, programmatically calling click() on an element) fail with an the following error being logged to the background script:
Unchecked runtime.lastError: Cannot access contents of url "". Extension manifest must request permission to access this host.
Is the documentation wrong about this API? Have I defined my permissions incorrect? Any help would be appreciated!

How to pass control to a new window(not popup) in selenium?

My site has a link which navigate to another site. I have to check whether the link taking the user to correct website. The following is the code i've written to pass control
selenium.click("link=target window");
selenium.selectWindow("Title of target window");
assertTrue((selenium.isTextPresent("content in target window")));
selenium.close();
selenium.selectWindow("null");
But if i run this i'm getting error like "Could not find window with title ... "
There is information about how the selectWindow() function locates the window here. In particular,
If you're having trouble figuring out what is the name of a window
that you want to manipulate, look at the selenium log messages which
identify the names of windows created via window.open (and therefore
intercepted by selenium). You will see messages like the following for
each window as it is opened:
debug: window.open call intercepted;
window ID (which you can use with selectWindow()) is "myNewWindow"

One time actions in Chrome API

I am making an extension for Chrome as a browser action. I need to know if there is any way to have some functions executed while installing the app. All of the pages that I have seen like "background" and "popup" execute everytime. I need to configure the extension and then use these parameters further in my extension.
Is there a way to do so or I will have to put a check everytime the browser starts.
Best practice is to use a background page and localStorage. Each time the background page starts check if localStorage.getItem('installed') === 'true' to see if it is a new istall or not.
Background pages start when Chrome starts vs browser action popups that start every time a user clicks the button.