Testing a live website with QUnit

Can live web sites be tested with QUnit? For example, can I write a test that says:

  • Go to google.com
  • Enter your search query
  • Click "Google Search"
  • Check if there are 10 results and 2 ads

Would QUnit be the right tool for such live testing?

+4
source share
2 answers

You can achieve this with qunit if qunit is the only tool / testing platform available to you, and the page you will be testing allows for GET requests.

How to do this qunit, you can make an ajax call on the page you are testing using JSONP and get a response. You then claim that certain elements of the answer exist.

For google, google itself has a very complex page structure in the search results, I would not even try to do something like that.

I would use qunit to test javascript components myself without dependencies.

If you are looking for another tool to accomplish this task, I would recommend Selenium, which will do exactly what you want.

Good luck.

+7
source

Do you want to test your own website or random website?

  • If you want to test your own site, you can embed a live site in an iframe and perform actions in the user interface in your tests.
  • If you want to test live websites such as google.com, you need to make this server side, since you cannot access them from javascript / QUnit.

When you where the owner of the site, for example google.com, can do:

var submitted = false; function starttests(){ if(!submitted) test("testInput", function() { expect(1); submitted = true; var dom = iframe.contentWindow || iframe.contentWindow.document; jQuery(dom).find('input[type=text]').val("Testing google.com"); jQuery(dom).find('form').submit(); ok( true, "form submitted" ); }); else test("testResult", function() { var dom = iframe.contentWindow || iframe.contentWindow.document; // Check for elements in dom. }); } iframe.onload(starttests); iframe.src = "http://google.com"; 
+5
source

Source: https://habr.com/ru/post/1385329/


All Articles