Fai*_* Mq 2 javascript testing automation npm
我正在寻找一个基于npm/javascript的自动化测试工具,我可以用它测试我的网站提供脚本输入值然后例如点击页面上的提交按钮等.到目前为止,我已经测试了Dalekjs但它似乎有很多问题,特别是Firefox,以及一些CSS选择器甚至在其他浏览器中也不起作用.
还有其他好的自动化测试工具是基于npm但不一定需要Selenium吗?
有一个非常棒的工具叫做Nightmare.js.首先它是一个高级幻影包装器,但是自从v2它被重写在Atom上.梦魇是基于webkit的.
梦魇可以无头地执行,但您可能需要配置服务器以使其正常工作.
为什么是梦魇?以下是官方网站的代码示例:
yield Nightmare()
.goto('http://yahoo.com')
.type('input[title="Search"]', 'github nightmare')
.click('.searchsubmit');
Run Code Online (Sandbox Code Playgroud)
比较:
phantom.create(function (ph) {
ph.createPage(function (page) {
page.open('http://yahoo.com', 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();
});
});
});
});
});
Run Code Online (Sandbox Code Playgroud)
所以你必须编写明显更少的代码.
为了让所有浏览器都能正常运行,请查看Selenium.它支持很多浏览器和平台.
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.com/ncr');
driver.findElement(By.name('q')).sendKeys('webdriver');
driver.findElement(By.name('btnG')).click();
driver.wait(until.titleIs('webdriver - Google Search'), 1000);
driver.quit();
Run Code Online (Sandbox Code Playgroud)
只是一个小建议 Selenium测试可能比噩梦测试更"笨重",我在Selenium测试中看到了很多"Promise hell"我以前的一个工作,所以在你开始之前,我给你的建议是使用生成器和/ co或其他一些控制流库.
| 归档时间: |
|
| 查看次数: |
3526 次 |
| 最近记录: |