I have a general question, which pretty much is, How do I test SOLR queries using Selenium?

Suppose we have a SOLR query JSON file, which pretty much looks like a huge pile of text containing values in form of Key-Value pair. From this file, I want to assess particular value(s), e.g. the title of an article list page which may have a lot of different title values. Then I need to match this value(s) to the front end to see if they are equal or not, e.g the SOLR query text/JSON file has a value like "title":"2006 Ford Expedition: Used Car Review". I want to test this thing with Selenium to see if it matches correctly to the article list page value.

If the SOLR results were a web page it will be easy to do this but since the SOLR query gives a text file, I can't access the value. And the SOLR query always gets updated so its result might change. Thus, I need a convenient affirm way to access particular values and test this scenario.

  • How these queries are executed, mean who execute these queries and provides the text files?
    – Dhiman
    Aug 7, 2015 at 18:43

2 Answers 2


I am not sure Selenium is the right tool to test JSON API's.

JSON Viewer:

But you could add a JSON viewer extention to the browser:

After installing the viewer, JSON will not be downloaded as a text file, but displayed as a text page.

Parse downloaded file:

You could also load the downloaded file from Java with a JSON Parser and then do asserts on the JSON object. Have a look at this blog post: http://crunchify.com/how-to-read-json-object-from-file-in-java/


But I would look at something like rest-driver to test the JSON return values, since there is no real need for a browser, unless you have a complex session setup. Also read this question for more API testing tools: https://stackoverflow.com/questions/12135309/automated-testing-for-rest-api

  • Thank you for all the links. I will upvote your answer as soon as I get the required amount of points.
    – Robben
    Aug 10, 2015 at 17:25
  • What if we are given the url to the SOLR search thus the JSON file doesn't need to be downloaded. Will the addons you provided still work?
    – Robben
    Aug 10, 2015 at 17:44
  • You query SOLR via HTTP GET and receive JSON, XML, CSV or binary results. If you are handed a URL with a search that page parses the retrieved data and shows it in another format. So no, since the plugins only help to display JSON data and not a website :) Maybe have a chat with the developer and see if they can assist you? Aug 10, 2015 at 17:53

I can tell you the approach, because we have we used similar thing in our project but not with Selenium. I think this will work with Selenium too.

First you need to open the text file in browser (Firefox) using Selenium (this can be done, launch browser and set the navigation URL which should be the path of that text file) and then move your focus to that Tab/Window (if not already there). Once your focus is moved, find the Key using the findElement or RegEx functions. Using a loop save all the Value(s) for that Key to a Excel file (not text file as comparison will be easy in Excel then text). Once all values are saved in Excel, pick value from Excel one-by-one using a loop (get the count of rows in Excel for starting loop) and compare the same to the front end values.

Update your excel for the comparison result i.e. if Values are equal mark 'Pass' in excel else Fail or Not Found. Then the Excel will show you the final result set.

By this way if result in SOLR text file is updated then that will update only your excel sheet values (which you founded by using RegEx) and that excel sheet is again compared to the updated values of Front end. Hence, update of SOLR text file should not affect your script (Assuming name of KEY is not changed or updated).

  • But what if the key value pair looks like "title":"2006 Ford Expedition: Used Car Review" and I want all values that has the key 'title'? Do I parse through each word until some condition is met?
    – Robben
    Aug 10, 2015 at 17:22
  • Yes, if your key name is fixed, lets say they are "title", "firstname", "lastname" etc. then you need to search each to these keys throughout your file and save corresponding values to a separate excel file. You need to do this, because your Key-Value has One-to-Many relation.
    – Dhiman
    Aug 10, 2015 at 17:27
  • I see, thank you! I will up vote your answer as soon as I get the required amount of points
    – Robben
    Aug 10, 2015 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.