Javascript Login Popup - selenium

Can you please suggest how to handle login popup on Chrome using Selenium :
Since org.openqa.selenium.security.UserAndPassword removed from Selenium 3.0 and above, how to progress with the login ?

Check these out 1 and 2.
The second video though used with Firefox explains that to pass a username and password through the url itself. For example when calling the driver.get() function you can pass the username in password of the page by the following.
driver.get("https://username:password#domain.com")
Website 1 however does it by passing it through Selenium's server and lists various other methods with out using the url.
Refer to link 1's methods 2 and 3 for use without using the url method.

Related

Selenium Chromedriver call to logout page not working

I want to write an automated test with Selenium using Chromedriver and Behat.
This scenario in question should go to a page, register a user, logout and register another user.
Now the problem is, on the website in question, after registration you get an annoying overlay, so that the logout button is not reachable anymore. I can either make the test fill out the overlay and complete it properly, which will take much more effort, or try to logout some other way.
My idea was to simply go to the domain again with /?event=logout added which normally works to log out the current user. However when I do this in the automation it fails, apparently because of a bad http response code.
Is it not possible to use a url like this with Selenium? Anyone have an idea?
You can achieve this with Selenium using a site that makes GET requests. So you can go to URL http://requestmaker.com/, fill the www.website.com in the Request URL, and 'event=logout' in the Request data, then click "Submit".
It's a bit hacky, so I would prefer using a GET request directly in the code, depending on your programming language... Something like so:
https://www.mkyong.com/java/how-to-send-http-request-getpost-in-java/
Some options would be:
Navigate to URL to logout and try to hide the modal via jQuery/javascript
After registration navigate to homepage and see if the modal is there and if you can logout as you should
Clear session and navigate to the page you need
Pick one of them.

Not able to verify text after login with selenium Webdriver script

I am trying to automate login functionality with selenium webdriver using TestNG framework. I want to verify the text after login like Hi [username#gmail.com].
This is the order in which links are present on page :
TrackOrder | Notification | Singnup | Login
My method of doing:
I clicked on Login (login window appears) and I sign in. After login
the order in which links are present on page are :
TrackOrder | Notification | Hi[username#gmail.com]
For verifying text after login :
I am extracting the xPath of web element Hi[username#gmail.com] and using getText() method to verify actual and expected value.
Actual problem:
As soon as I run script , it logs in successfully but when I extract the text of web element it is printing signup. Though login is done successfully why is it showing up singup?
The reason for printing signup maybe that either the XPath you gave, is not explicitly identifying the username element and just give the element next to Notification element, or the signup element text is changing to username text after login.
So, better to create unique XPath for your element and wait for some time before using getText() method.
Thread.sleep() can be used if the text of the element is changing on login as selenium will execute the method before the change in text value.
Try to use Absolute Xpath of the Web Element.

Showing file selection UI : Integrating Dropbox with OAuth 2

I am trying to create a web page which will allow my user to upload a file to my S3 storage. For choosing the file user can use Google Drive, Dropbox and also local system. Am facing issues while implementing the Dropbox part of this.
Am using this technique for integration(using core API and OAuth 2).
First when user chooses Dropbox i am opening an HTML page in an IFrame. Here I have an authorize button which will open the authorize endpoint mentioned in the above link. This link shows me X-FRAME-Options error inside the Iframe so i had to open this link as a popup to work.
Is there a way around this? I'd like the authorize URL to open in the same iframe by using location.href.
Also when i open it as a popup, after the user logs in successfully the redirect_uri which i pass i getting opened in the popup. I had to do some unconventional setInterval coding to go around this. Can someone suggest a solution for this as well?
I also tried using CSRF tokens as mentioned in Smarx's blog but this also gives me the same error.
EDIT :
#smarx i tried using dropbox.js and it works fine. Stuck at one place
I used the OAuth popup driver and have a button which says sign-in.
First on load i create the client and then the popup driver as below
client = new Dropbox.Client({ key: client_id });
client.authDriver(new Dropbox.AuthDriver.Popup({
receiverUrl: "http://localhost/uploadCare/dbcallback.html"
});
);
And in the call back html i am writing
Dropbox.AuthDriver.Popup.oauthReceiver()
as mentioned in the docs.
But this does not take me back to the original page and show me the list of files.
I particularly did not understand this part of the explanation
"To use the popup driver, create a page on your site that contains the receiver code, change the code to reflect the location of dropbox.js on your site, and point the Dropbox.AuthDriver.Popup constructor to it."
Could you please help me out here.
You definitely can't put dropbox.com into an iframe, for security reasons (e.g. clickjacking).
A few suggestions:
Can you just use the Chooser for your use case? That would certainly be easier for you and your users.
If you can't use the Chooser, is there a reason you're not using dropbox.js? It has a popup auth driver that will pretty much just take care of all this for you. The redirect will definitely happen in the same window as auth, so communication between the windows (usually via localStorage) is generally necessary. This is already done in dropbox.js.

capturing a browser refreshed event using Selenium Web Driver

I am writing a program to automate link validations in a site. Our site is having more than 400 links per page and we need to open each link and see it is returning a valid page i.e 200, there are other requirements as well to check if the page is a 404 redirection page etc. It means to validate 400 inks it will take about 30 minutes or so.
My design is to integrate this with the Front-End (Selenium) automation in a way that each time the browser loads a new page or browser refreshes it will trigger a new thread by passing the page source for validating all the href available.
We are not following a page object model otherwise I could trigger this in my each page.
Question here is that is there any way we can listen to a browser refresh or page load event using Selenium Web Driver?
Correct me if I don't understand your question, but page_refresh and page_load_event can be two very different goals for you, if you are dealing with AJAX. You can try this article about the AJAX part
and this one for selenium custom events synchronization.
This solution here is the most actual I could find.
Actually Selenium is JS driver so this answers can be helpful if you want to try it too:
check-if-page-reloaded-or-refresh-in-js
is-page-reloaded-or-refreshed-using-jquery-or-javascript
post_detect_refresh_with_javascript

Selenium enter text to field without an identifier

I wonder if anyone know hoe to enter text into a field without any identifier. What happens is that i go to a website and are displayed a log on page in front of the web browser. If i now use F12 will I receive all the info about the page in the background except for the log in page.
Is there a way to blindly enter text, press tab, enter some more and then press enter?
I will make wild guess: That log in page uses HTTP basic authentification and you need to get to that page using Selenium.
If so, simply use this:
driver.get("http://username:password#your-test-site.com");
Where driver is healthy instance of WebDriver
EDIT
In my testing, I had the same issues as you are having. So try this:
Go to your test site manually
Manually log in
Grab the URL you have been redirected to. In my case its something like http://my-test-site.com/faces/pages/admin/admin.xhtml
Use that url to get to the site - i.e: driver.get("http://username:password#my-test-site.com/faces/pages/admin/admin.xhtml");
Assuming you are using firefox, you can take a couple of approaches:
Create and use a profile where you have the username and password saved.
Try whitelisting your domain on Firefox preferences like this:
profile.SetPreference("network.automa
tic-ntlm-auth.trusted-uris", "domain.com");
driver = new FirefoxDriver(profile);
driver.Navigate().GoToUrl("http://user:password#domain.com");