Penguen
Penguen

Reputation: 17288

How can i make automation test my json webservices by selenium?

i want to make an automation test alot of web services (json). How can i use that? my json : { data: [ { id: "TPN_IT_2010", type: 1, name: "Esso,NAPOLI", a: "VIA FORIA, 200, NAPOLI, 80100, Italy", b: 40.859654, c: 14.262477, d: [ ], e: [ ] }, { id: "TPN_IT_2005", type: 1, name: "Esso,Napoli", a: "VIA GALILEO FERRARIS 44/50, Napoli, 80142, Italy", b: 40.850298527, c: 14.2760413885, d: [ ], e: [ ] } ] }

My selenium node.js is that:

var webdriver = require("selenium-webdriver"); var chrome = require("selenium-webdriver/chrome"); var capabilities = webdriver.Capabilities.chrome(); process.env["PATH"] += ":/home/user/src/selenium/"; var options = new chrome.Options(); var driver = new webdriver.Builder(). withCapabilities(options.toCapabilities()).build();

driver.get("http://abc.net/sss/v1/contents//abcd/?m=x&lat=40.8529717&y=14.265241&radius=1");

driver.getTitle().then(function(title) { console.log(title); });

driver.quit();

How can i access my json web services :
AVAILABILITY
HTTP STATUS
Json response Format
Fields(Right information)

Upvotes: 1

Views: 2444

Answers (2)

Arthur Ronconi
Arthur Ronconi

Reputation: 2428

Could be the answer?

  describe('json', function () {
    it('json contents', done => {
      driver.get(url + '/data.json')
      driver.findElement(By.tagName('body')).getText().then( v => {
        expect(v).to.equal('{}')
        done()
      })
    })
  })

Upvotes: 0

Robbie Wareham
Robbie Wareham

Reputation: 3438

Are you sure Selenium is the right tool?

If you are testing web services then there is no need to open a browser, therefore no need to use Selenium.

Instead of instantiating a WebDriver instance, you can create a HTTP client and make requests, then assert the response in the same way as you would assert on Selenium. You can assert on response codes, headers, response data etc. It will also allow you call other methods such as POST, PUT, PATCH, etc whereas using a webbrowser will restrict you to GET. Also, your tests will be much faster, easier to multi-thread and can run on a build server without the need for a grid.

I am not up to date on the best HTTP Client library in NodeJS but I am sure there are plenty of options

Upvotes: 4

Related Questions