Submitting data to form and interacting with website, automation - java

Suppose I have a website that I can log into (at any time) and submit data to every x hours (click a link visible once logged in), how would I go about automating this process?
I have built a gui that provides the user (for now me, for my own convenience) an interface with some information, lets the user type in the log-in info and a button for starting a scheduled and repeated task in a ScheduledExecutorService but I am stuck at that point. Currently I use the Desktop api and browse() and rely on the user having logged in and just browse the url of the clickable link.
Knowing the URL of the loginsite, how do I submit the login info from my application to the the loginform of the website and let the website process it? (and let my app know the login was sucessful) and then click the link that will be visibile at a different URL once the login succeeds?

Looks like you need Web Services. Try exploring WSDL or REST api.
EDIT : Looks like you are trying to use Selenium which is a functional test framework. Set it up like the program describes at the end of the getting started page. After that you should be able to access the html page elements as provided in the tutorial.

If the webapp doesn't expose some kind of web service you cannot automate login procedure or any other action on the site.
If the website is your project, than you can implement web methods that allow you to achieve what you need.

Related

get from rally graph

I'm developing a Dynamic web Project in java, and the goal is upon click on button to fetch the "ITERATION BURNDOWN" graph from https://rally1.rallydev.com.
my question is do i have to know the rally api in order to get this content or just to go to the appropriate url and search there the graph?
i login successfully to the rally (used this link for the login: http://www.mkyong.com/java/how-to-automate-login-a-website-java-example/).
after i login successfully i couldn't get the url with the graph. it's just returning the landing page content.
pls help,
Thanks
I assume that you refer to IterationBurndown on Reports>Reports page, which is served by a legacy analytics engine.
To get the appropriate URL you may need to install IterationBurndown report wrapped in an app from AppCatalog on a custom page in Rally. I cannot confirm a java scenario, but the URL of that custom page can be used with javascript, by making an html file with this custom page embedded using iframe, for example:
iframe.src = "https://rally1.rallydev.com/#/12345d/custom/6789";
The steps are:
create a custom page
install IterationBurndown report from the AppCatalog as an app.
At least in the javascript app case, the URL to IterationBurndown on Reports page will not work for this purpose, hence the extra step of using a custom page.
When you say that you get a landing page, I am not sure if you are referring to login page or home page. If it is the former, it means authentication has not been handled. Legacy IterationBurndown report wrapped in an app will not work with newer ApiKey. That's too bad because ApiKey, unlike LoginKey, works with Java as well, unlike the legacy LoginKey which works in the browser (with html/javascript apps) only.

selenium page object model: waiting for java script to complete

I'm using the selenium page object model to test a website. We have access to the sandbox PayPal account which allows us place test PayPal orders with a mock account.
My problem is on the sandbox PayPal login screen when I click login with the account I have created some java script (I'm guessing) displays an animation saying "Authenticating your information Logging you in"
When this happens my page fails because the is loaded() is expecting the url to be different but because the page doesn't start to load the next page until after this javascript completes the url is not correct.
I could stick a hardcoded wait for this login to take effect but does anybody know a better / proper way to handle this?

Sending credentials from PHP web application to Java web application

I have a web PHP web application that has a link to a java web application. The php application has a login page, and a link to the the java application, but not every user has permission to access the java web application. What I was trying to do is send user credentials from the php application to the java application, and then the java application checks the credentials and if correct logs in the user. I was thinking of using http headers to do this.
So my question is what is how to send user credentials from a PHP application to a java application?
If it helps I am using a Java web framework called Vaadin.
Do a normal POST request from the PHP application to the java application. This can be done as simply as having a normal HTML form in the PHP application, set the form's method to "POST" and action to the java application's URL. If you want to catch HTTP parameters in a Vaadin application, you can do it by using request handlers (https://vaadin.com/book/vaadin7/-/page/advanced.requesthandler.html).
Then a few words of advice or something to at least consider. If your login page is in the PHP application and your "admin" application is the Vaadin application, then I discourage you from doing the credential checking in the Vaadin application. This is because when you enter the Vaadin application, a new application instance is created. This means that your UI will be initialized and whatever else you do in the UI's init method. What you probably want to do, is to hinder the user from entering the Vaadin application unless she is logged in - which means that you need to do the credential checking somewhere else - for example, have a separate servlet whose only responsibility is to log in the user. If login is granted, then give access to the Vaadin application, if access is denied, forward the user to the PHP login screen. The next question is, how do you hinder the user from accessing the Vaadin application until she is logged in? Typically, this is done using servlet filters.
I highly encourage you to use a 3rd party framework for doing the authentication and authorization. Take a look at http://shiro.apache.org/, it's easy to install and seems to work nicely together with Vaadin. All you need to do is to configure it and implement a login screen, the framework will take care of the rest.
If I understood your question, you want to be able to provide an "auto-login-link" to some specific users that are logged in to the PHP application. This link should automatically login the user to the java application, right?
Without knowing any details about this case, like are both apps running on the same domain or do they use the same database (same user credentials in both apps), etc., I would propose the following solution:
Create an action (link) on the java application, which receives the necessary parameters (as GET) needed for creating the session (probably userId is sufficient), timestamp and a signature of all parameters. For example:
http://javaapp.example.com/autologin?userId=123&timeStamp=123456789&sign=hj23kh4j234jk324h
Where the signature is calculated with some strong encryption algorithm. Then you verify that the signature is correct at the receiving end (java app). If it is correct, you create the session. Signature calculation could be something like:
$signature = sha1($userId . $timeStamp . 'some salt' . $sharedSecretBetweenBothApps);
With the timeStamp you are able to check that an old link is not used. For example not allow older than 15 min old links and store used links in the java app to make sure they are never re-used. You do not have to keep history of links older than the expiration time.
Another idea, as discussed in the comments, is creating an API on the java side, which is able to provide a one-time link.
The sha1 algorithm is probably not strong enough, but shows the idea and is simple to implement.
Does this answer your question?

Login system from different domains

the company I work has assigned me the task to create a system to login in every of the company products. These products are in different domains.
We want it to be like google. When we login to our mail account, we are automatically logged in in google+, google docs, youtube, etc.
The idea is to have a main application in Java, were all others, in PHP, would login to. Everytime a user goes to another company site, it will check the main application to see if a login has been made or to login that user. I was thinking about doing this with OAuth but as I read further I'm beggining to think that OAuth was not created for this.
How can I do this? Is there any example/library available on the web?
Thank you.
The term you're looking for is Single Sign On. One way to do this is using SAML.
You can create a simple API, as one logs in, trigger it to send a request to another site and log them in and set their cookie.
This can be slightly done by using the OAuth or you can go through your parent company too. Same like, we first login to gmail so we get session login to all the child sites like google doc, and etc. So, you can also go over the curl extension. Use it to login user to your child sites based over BASIC or DIGEST auth. system.

Is Multiple browser window with single time login possible in Java

I have a simple requirement. I have an web application which has a login page, a dashboard and few other pages.
If the user wants to open the application in multiple browser window from a single computer, then I want the user to login only once in first browser window. From next time onwards, whenever user hits the application URL in another different browser window(or tab) in the same Computer, then the application should redirect the user to dashboard without a fresh login. So that user does not have to login each time he opens the application in another browser window.
Is this complete scenario possible in Java/J2EE using JSP and Struts. Here I am using container managed login in Struts for the authentication(login). I need to maintain different HTTP sessions for each window(this is inherent requirement of the application).
Plz guys, waiting for a quick reply as I am stuck with this very urgent requirement from my Client.
Thanks in advance.
Avijit
In the same browser (IE, Firefox, Chrome etc), this is easily achieved with (session) cookies etc.
After login, just set a cookie that subsequent page loads will read from.
Read this question for some good additional related information:
Managing webapp session data/controller flow for multiple tabs
As #Edwin Buck has already mentioned, have a look at OpenID (or a similar single-sign-on framework):
OpenID
You've also got the option of using the client's IP address, but this is hideously insecure.
Look at the single sign-on architecture, or other solutions (like OpenId) which do authentication without end user interaction.

Categories

Resources