I am currently working on learning selenium and my current requirement is to read an API JSON response when a certain button inside my application UI is clicked.
I mainly use Java and selenium but I have the flexibility in using any other language.
The click triggers an event which hits an API and a response is received. Hitting the API directly without going through the UI is not an option.
Additionally, when using Developer Tools in chrome, i can see the response in the "Network" tab. If there is any way that i could just read the "Network" tab, that is also acceptable.
Related
I am trying to load a page, and I am automating the process of checking for a POST request after a button is clicked.
In order to do this, I need to clear the Network tab of all previous entries before the button is clicked, otherwise it will not show up on the list for some reason.
Is there a way to do this via logging or some other means in Selenium Java?
As far as I know, there is no way to interact with Chrome's dev tools as you intent to. Alhough, if you are interested in obtaining/parse data from the Network tab in Chrome you can do that following their quick tutorial in their website here.
I don't know what is you idea but here I leave you 2 cents.
Perhaps you could access this data and work it elsewhere instead of constant refreshing.
Here is a similar question to yours.
I need to open a browser with URL and then wait till person clicks a special button. And if it happens, return true. Can I implement it with java tools or should I use javascript?
You should use JavaScript. Java is a Server side language, so all processing of Java code will be completed before the user has the chance to interact with the page. JavaScript (traditionally) works on the client-side and is commonly used to capture user interactions with the browser.
yes, Java Script or any frame work that builds on Java script like Jquery works for you. If understands you correctly,
create Hyper link
Browse the page that you needed
Place HTML button on the page, write onClick logic on that button to return true.
In browser(Firefox or Chrome) user performs many actions such as filling input or pressing submit button etc. Is there anyway(in Java) where we can record these actions(which component he clicks or Xpath of that element) on client side? Selenium has Webdriver but i am unable to find if it can does this.
There are a Java library called JSFlight.
This tool is splitted into three main parts:
Recorder - it's the set of the javascript files, that you should insert into your html document. You can configure which types of events you want to track. It can work with iframes too.
Player - this is the main program/library which plays recorded events.
Server - it's the wrapper upon the Player. Starts a standalone server with rest api. Uses the MongoDB.
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 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.