I am a bot developer in selenium webdriver Java and I'm using a browser HtmlunitDriver headless but it's complicated when I have to deal with javascript, so, which is better when I have to automate page? Sending HTTP get and post requests or continue using webdriver?
I'm confused because, for example, how can I click a button and wait for a page to load (example: when I open a page like Ad.fly) and I have to wait 5 seconds until the button is ready sending http request, this is what I am confused by, thanks a lot for your answers!!
Use HTTP requests if you just want to make calls (i.e. to REST services). Use selenium (or other web automation tools) if you need to simulate browser behaviour (i.e. run javascript in the page).
HTTP is generally preferable if you have the option - services are more stable than page structure (particularly if there's a published interface) and are more oftened designed to be machine-readable. Web pages are designed for humans using web browsers, so they can change frequently, and adds a lot of overhead which doesn't make sense in a machine interface.
So, I'd suggest - look through the sequence of user actions you're trying to automate. If you can express those as a simple sequence of HTTP requests, I'd do it that way. If you need to run client-side javascript, or use other browser functionality, use selenium.
Related
I want to be able to use Java to tell it to go to X url when X browser is open/running (my lingo is terrible). (Firefox/Chrome/IE is already up, and I want it to go from the default page to let's say Twitter.)
Most of the solutions are using java.awt.Desktop to launch native browser with a url in it, but that isn't useful if I want to change the url later on. (Already on Twitter-Home Page, but want to go to Twitter-Contact Us afterwards.)
The other solutions I've seen involve using Selenium WebDriver, but I also need to eventually learn how to basically force the Java to read a long list of URLs off an excel and simply verify that url isn't dead, and then do this on the Native Android browser, for example. So the Selenium might not be the right choice. Granted, you can also tell me this is an awesome choice for this too if it truly is. I haven't really been exploring Selenium.
Sorry for asking such a basic question. Company wants QA Automation without training/hiring an Automation QA. My end goal (aside not getting canned), is to see if I can get a bunch of urls to load on specific browsers. I can sort of (praying) be able to do stuff with it afterwards.
A simple trick would be to create an add-on( if you know javascript ) which will be quite similar in chrome and firefox (for IE I have no idea in my days it needed BHO) and send websocket commands from java to your addon. But this needs a java websocket server running where your addon will connect when the browser opens. Rest of communication can be carried upon the protocol lines of your requirements.
There are multiple parts to your question.
Read urls from excel.
Use Apache POI to do the same. Selenium code can use the same.
Check that the urls are not dead.
Use any java http client, (apache) to do that without even opening a browser. If the link is dead, it will be dead for all the browser.
Open the links in a multiple browsers.
Selenium is perfect for this. I am assuming that after the page is loaded you have way of validating that the page is correct. Selenium is very powerful here.
Target native android browser too.
I do not know of much difference between this and the previous question unless you are also testing site display based on browser size. The browser is more or less the same as chrome with webkit rendering engine.
I want to verify API calls/json files that are generated at the time of performing action like save, edit from browser. We can see those API calls in Developers Tool of chrome browser under network Tab.
So I want to Test those API calls using Selenium. How can I achieve this ?
Thank you in Advance.
Selenium doesn't have a built in functionality for you to achieve that.
Basically, if you click the Save button from browser using Selenium, you could only get the requests and responses using a 3rd party library like the Fiddler API.
Another way for you to do that is to create the requests yourself using the HTTPRequest or HTTPResponse classes (these are in C#, probably that in Java they have a different but similar name).
And using a tool, I suggest doing it with JMeter, it's open source, can do it by himself or can be integrated with Selenium.
Another options, "Selenium based" would be to use a headless browser. I know that HTMLUnitDriver has this built in, not sure about PhantomJS or others.
I'm using SWT.Browser (java) and am wondering if there's a way to get a listener that hears when ajax requests are made, received, etc.
Is there a way to intercept them and manipulate them before they come in, etc?
No, there is no publicly available API for that.
However, you can write APP plugin for SWT, though it is applicable to IE only. Or for Firefox or Webkit or IE you can write a local proxy like fiddler.
This question might be very basic.
Till now I thought a command to print a webpage can only be initiated at the client side.
(window.print when using javascript)
But I came across http://juixe.com/techknow/index.php/2008/01/17/print-a-pdf-document-in-java/ which states about printing using Java. I think this seems to be related to some desktop client and the same may not be possible in a web client. Can anyone confirm and explain this?
You can't execute server side code on the client, so the only way to do it in browser is through javascript or using plugins/flash/java applets.
You could print using java, but for that java needs to run on the client.
A website can ask the browser to open its print dialog (Google Maps does this on the "print directions" page, for example), but it can't actually force the browser to print anything. (If it could, you can be sure that advertisers would use it to print ads on your printer.)
A Java application running locally with sufficient permissions can print, just like any other desktop application. That has nothing to do with web pages.
Don't confuse Java and JavaScript. When trying to use Java within a browser, you'd have to look into using applets. A Java applet could definitely be used to do the kind of work you'd normally have a rich client do from within a browser.
Java applets could also receive events sent out from a server via sockets or some other mechanism, although I'm not certain if security constraints would allow it. Also seems a bit of a roundabout way to do things.
Remember that web browsing is a client-side-driven affair. There's some push models in certain infrastructures (I believe it's possible using JavaServer Faces). But those are probably just a sort of polling mechanism initiated by the client that is abstracted away to look like a server-side push.
I need some kind of webbrowser backend (don't know if it's proper name for such thing). Generally I need high abstraction of html page with controls, ability to create events (button push or selecting an item from combobox), javascript interpreter, etc.
Are there anything of that kind?
I think you want something like HtmlUnit. From the page:
HtmlUnit is a "GUI-Less browser for Java programs". It models HTML documents and provides an API that allows you to invoke pages, fill out forms, click links, etc. just like you do in your "normal" browser.
It has fairly good JavaScript support (which is constantly improving) and is able to work even with quite complex AJAX libraries, simulating either Firefox or Internet Explorer depending on the configuration you want to use.
You might also want to check out Selenium which lets you control a real browser programmatically.