admin管理员组

文章数量:1314488

I am looking for an npm/javascript based Automated Testing tool with which I can test my website providing scripted input values and then for example clicking submit button on page etc. So far I have tested Dalekjs but it seems to have lots of problems especially with Firefox, plus some CSS selectors are also not working even in other Browsers.

Is there any other good Automation testing tool that is npm based but does not necessarily require Selenium?

I am looking for an npm/javascript based Automated Testing tool with which I can test my website providing scripted input values and then for example clicking submit button on page etc. So far I have tested Dalekjs but it seems to have lots of problems especially with Firefox, plus some CSS selectors are also not working even in other Browsers.

Is there any other good Automation testing tool that is npm based but does not necessarily require Selenium?

Share Improve this question asked Feb 15, 2016 at 16:13 Faisal MqFaisal Mq 5,5544 gold badges36 silver badges40 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 6

Nightmare.js

There's a really awesome tool called Nightmare.js. First it was a hight-level Phantom wrapper, but since v2 it was rewritten on Atom. Nightmare is webkit-based.

Nightmare can be executed headlessly, but you'll probably need to configure your server to get that working.

Why Nightmare? Here's a code sample from the official site:

Nightmare.js

yield Nightmare()
  .goto('http://yahoo.')
  .type('input[title="Search"]', 'github nightmare')
  .click('.searchsubmit');

Comparing to:

Phantom.js

phantom.create(function (ph) {
  ph.createPage(function (page) {
    page.open('http://yahoo.', function (status) {
      page.evaluate(function () {
        var el =
          document.querySelector('input[title="Search"]');
        el.value = 'github nightmare';
      }, function (result) {
        page.evaluate(function () {
          var el = document.querySelector('.searchsubmit');
          var event = document.createEvent('MouseEvent');
          event.initEvent('click', true, false);
          el.dispatchEvent(event);
        }, function (result) {
          ph.exit();
        });
      });
    });
  });
});

So you'll have to write significantly less code.

BUT IT'S WEBKIT-ONLY


Selenium

In order to get something working in all browsers, take a look at Selenium. It supports really many browsers and platforms.

var webdriver = require('selenium-webdriver'),
    By = require('selenium-webdriver').By,
    until = require('selenium-webdriver').until;

var driver = new webdriver.Builder()
    .forBrowser('firefox')
    .build();

driver.get('http://www.google./ncr');
driver.findElement(By.name('q')).sendKeys('webdriver');
driver.findElement(By.name('btnG')).click();
driver.wait(until.titleIs('webdriver - Google Search'), 1000);
driver.quit();

Just a small advice Selenium tests are likely to be more "bulky" than nightmare tests and I've seen quite a lot "Promise hell" in Selenium tests on one of my previous jobs, so before you start, my advice to you would be to use of generators and co or some other control flow library.

try http://phantomjs/

It might be an excellent alternative to Dalekjs. Phantom.js is runnable without a UI, scriptable via JavaScript and is used for automating web page interaction. It's a WebKit with its own JavaScript API. It has fast and native support for most web standards: DOM handling, CSS selector, JSON, Canvas, and SVG. You can use scripted input values

Here is a sample usage:

console.log('Loading a web page');
var page = require('webpage').create();
var url = 'http://en.wikipedia/';
page.open(url, function (status) {
  console.log('Page loaded');
  page.render('wikipedia.png');
  phantom.exit();
});

I also had a similar requirement, I did below investigation which would be helpful:

NightmareJS is actually based on PhantomJS. It works very well even for a non-dev. In reality automated testing truly depends on many situations and the type of application tested. You need a super fast way to visually see if changes to the code is affecting the app visually and also to some degree its logic. For logic there are many other frameworks for that like selenium frameworks. No need for plex coding as you want to be able to view the application or test results quick, modify the variable or elements that neeeds to be tested and verified.

本文标签: Which javascript Automated Testing Tool to useStack Overflow