How to start browser in WebDriver with custom localStorage set - html

I want to speed up my Selenium tests and noticed that a lot of time is being spent on login procedure.
Login on web application is implemented via localStorage session token (probably OAuth 2.0). I know how to set it once a browser starts and login page loads:
localStorage.setItem(key, value)
It works great. But is it possible to make the browser to pick up custom localStorage using Selenium (Java).
Is it profile?

Well this works for me in python
driver.excute_script('javascript:localStorage.(funtion of localStorage)')
so I suppose well you can set up a validation token like I use for test, and of course I get my auth_token from the database first, but it works like this
driver.excuteScript('javascript:localStorage.token="your validation token";');
should work

Related

Embedding credentails in url to load website using selenium webdriver

I need to load URL which has authentication pop up. I used http://username:password#exampl.com format to access the website via selenium webdriver on chrome browser.
But this support seems t be dropped in latest chrome browser, So loading the url is not successful. Browser keeps loading for a long time with no response from server.
Is there any alternate way to overcome authentication pop-up with selenium webdrier ? I know we can use sikui,autoit etc.But i need to run the same code on many platforms - Win/Mac/mobile/tablet.
So please let know how to overcome this.
I am using Selenium 3.4.0 and Chromedriver 2.31, and loading a URL with authentication credentials works fine for me.
As per I know chorme stop URL authentication from chrome 60.x version.
You can try below code or downgrade your chrome version
The Alert Method, authenticateUsing() lets you skip the Http Basic Authentication box.
WebDriverWait wait = new WebDriverWait(driver, 10);
Alert alert = wait.until(ExpectedConditions.alertIsPresent());
alert.authenticateUsing(new UserAndPassword(username, password));
Hope it help you :)

How to close browser popup in robot framework?

After login in Chrome browser, I am getting a save password popup from the browser. I want to handle that popup and want to close that using Robot Framework
Browse popup window
Thanks
This question has been asked and answered before with a pure Python context. This answer continues on this SO post for a working Robot Example.
The popup you see is generated by Chrome itself. It's not an HTML alert. For this reason none of the Selenium2Library keywords will have any effect on it. Nor wil settings cookies or javascript.
These settings can be manually set using the chrome://settings link. Go to advanced settings and then scroll down to Passwords and Forms. Untick the second item and this will prevent the popup.
To do the same automatically in Robot Framework the WebDriver needs to be started with additional preferences:
Chrome With Preferences
${chrome_options} = Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
${prefs} Create Dictionary credentials_enable_service=${false}
Call Method ${chrome_options} add_experimental_option prefs ${prefs}
Call Method ${chrome_options} add_argument --disable-infobars
Create WebDriver Chrome chrome_options=${chrome_options}
Go To https://secure.url.com
This key things here are credentials_enable_service=${false} where it is important to use ${false} and not false, as the latter is interpreted as a string and then added to Chrome as "false" instead of the correct value false.
The second item is that preferences are not added as arguments but through assigning a dictionary to the prefs property of the ChromeOptions() object like so: add_experimental_option prefs ${prefs}
I do not think this is real to be honest (as it's property of the browser.) Are you having issues with that? The only thing you can dismiss is javascript alert and probably the best way to handle this is:
${alert} = Get Alert Message dismiss=${dismiss}
I have this in my test teardown with Run Keyword and Ignore Error, it makes me able to fetch optional js alert content and debug (also dismisses it do the rest of the suite can be executed.)
Three Ways To do do it.
1) Many a times, Once pop-up appear on screen and Disappear a cookie is set which you can view in developer console-> application. If you set this cookie with value using Add Cookie keyword. Pop- up wont appear.
2) if first doesn't work, then open developer tools and monitor the local store from developer tools -> application and close the pop-up. U will notice some variable with a value is stored in local storage. You can set that value using your script and u wont see the pop-up while executing variable.
3) If first and second doesn't work, the pop-up is most likely linked to a javascript variable. set java script variable using Execute Javascript Keyword and your problem must be solved.
Talk with your dev team, to see which way will work for you.

Is it possible to use the cast API from a chome app? how to bypass the receiver selection popup?

Does anyone know, is the cast API supported for use from a chrome app? It initializes fine, says there are receivers available but I can't get a session - when I call requestSession nothing happens at all, neither success nor error callbacks are called, no window is displayed.
Maybe I'm approaching this all wrong...what I'm trying to do seems like it should be relatively straight-forward, but it really seems like google has deliberately prevented this. All I'm trying to do is hook my IR remote up to my chromecast for media playback controls (play/pause/seek). Even if the requestSession method worked, it really wouldn't give the user experience I want - it would still require the user to select the receiver from the popupmenu UI whenever they want to use their IR remote - far from friendly. Instead I'd like to be able to pre-configure which chromecast the IR remote is bound to...and then it would always just connect to whatever app/session is currently running on that receiver to issue play/pause/seek commands.
I could implement this as a browser extension instead, and I'm sure I could get it functional that way...but that would be even less user-friendly (not to mention I'm already using some app-only APIs for the IR-receiving side of it which would have to be re-worked to other methods).
edit: Ok, after a bit more looking I've found this which I guess mostly answers my question https://code.google.com/p/chromium/issues/detail?id=287254 ....but the question about the popup still stands...even if using an extension is there any way to bypass the reciever-selection popup that requires user interaction?

Flash UrlLoader - prevent or suppress authentication dialog box

I have a rssfeed application made in Adobe AIR. It uses the UrlLoader to read the feeds. I need the application to never prompt the user to enter password for a website or accept a certificate of a website if is no longer valid. I prefer to have it fail instead.
I have setup the event listeners for IO+Error and Security_ERROR but that is not enough
Sample urls(this may not work in future)
http://www.dawnanddrew.com/rss2.xml (asks for user and pass atm)
I had another issue with a feed that even if it was a http url the website redirected the loader to https and then the certificate validation failed and the user was asked to accept the certificate. I need this to fail (I mark failed feeds and the user can check them when they want to find the issue and fix them or remove them)
Using AIR (which you are), you can actually tell the application to NOT handle authentication.
var request:URLRequest =new URLRequest("http://www.dawnanddrew.com/rss2.xml");
request.authenticate = false; //default is true, so you need to tell your request to not handle authentication
Then it will fail with an IO error instead of prompting for credentials.
Documentation
Note however, this will only work in AIR and is not a supported property for flash player.
You cannot do it this way. Now, the server returns specific status and the browser reacts to it by showing you a login dialog box. You cannot do this directly in flash and you cannot get default login button. You need to implement this by your own. The perfect way to do so is to check (server side) if the user is logged in and if not - return status ok (200) with an error message (let's say JSON). This specific message would be read by the flash client and a login screen would be shown (custom made). You will also need to implement the login feature by yourself :)
Sorry for the bad news, but this is the way it is with flash.

how to exchange variables between extern iframe and site

for developement reasons (working with facebook-connect) i put the connect iframe in an iframe. on that way i am able to work on the connect-thing independent of my ip and don't have to develop on the live-server.
the iframe holding the connect-button iframe is on my server, accessing the same db-server as the developer version (developer version is running on localhsot).
as far as good ... BUT
how can i let the parent site know, that the user has connected, so that i get his profile-picture displayd as reaction to this?
how can i react in generally on an action/event/JS in an iframe? is there a way?
can the iframe post data to the parent site? like a time-stamp and fb_userid?
if the iframe stuff doesn't work ...
i thougt of saving the ip to the fb_userid (to db) and check matches ... but i don't like this idea.
You can pass variables to frames using query string format through src attribute of the iframe, eg:
<iframe src="mysite.com?var=test"............>
Well thanks to #Sarfraz Ahmed, your post was the inspiration for my solution:
With the src of the iframe, I send the current session id as GET parameter.
<iframe src="http://www.online_host.com/scriptxy.php?id_session=<?=session_id()?>"></iframe>
Then the script in the iframe makes a callback after some action, like
<script>
location.href="http://localhost/localscript.php?id_session=<?=$_REQUEST['id_session']?>&parameters_here=something";
</script>
It should be noticed, that the GET parameters name has not to be "sessionid", or "sessid", because this is not allowed with the most apache installations.
In PHP localscript.php, you do something like:
session_id($_REQUEST['id_session']);
session_regenerate_id();
$_SESSION['param1'] = $_REQUEST['param1'];
...
Now you can access the sessiondata in your current locally running PHP. Together with a triggered AJAX request interval this works good enough for development.
The thing is, i'm using CodeIgniter (with PostgreSQL and the session-plugin ecko) and getting a memory problem in the PostgreSQL driver script, which i didn't figure out until now.