我正在学习本教程 http://engineering.wingify.com/posts/e2e-testing-with-webdriverjs-jasmine/
第一部分要求创建testfile.js
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.chrome()).
build();
driver.get('http://www.wingify.com');
当我运行node testfile.js
时,我能够让浏览器运行我创建了testfile.js
$ cat testfile.js
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.chrome()).
build();
describe('basic test', function () {
it('should be on correct page', function () {
driver.get('http://www.wingify.com');
driver.getTitle().then(function(title) {
expect(title).toBe('Wingify');
});
});
});
我到达运行jasmine-node
的部分$ jasmine-node testfile.js
Finished in 0 seconds
0 tests, 0 assertions, 0 failures, 0 skipped
预期的行为是它启动了浏览器,但这不是我遇到的。
答案 0 :(得分:4)
尝试jasmine-node --matchall testfile.js
或jasmine-node testfile.spec.js
,默认情况下,jasmine-node会搜索文件名中包含“spec”的文件。
答案 1 :(得分:2)
答案 2 :(得分:0)
我有同样的事情。 driver.getTitle()是异步的,因此Jasmine在返回任何内容之前就完成了。我尝试了几个使用driver.wait()的东西,但是无法使异步正确。
最后我使用Jasmine waitsFor - 等待真正的结果,或者它有自己的自定义超时。
下面的示例稍微复杂一点,因为我加载Google,然后搜索结果上的页面标题。
通过这个例子,您不需要设置全局Jasmine超时,这对我来说无论如何都不起作用。
describe('basic test', function () {
it('should search for webdriver and land on results page', function () {
var match = 'webdriver - Google Search',
title = '';
driver.get("http://www.google.com");
driver.findElement(webdriver.By.name("q")).sendKeys("webdriver");
driver.findElement(webdriver.By.name("btnG")).click();
// wait for page title, we know we are there
waitsFor(function () {
driver.getTitle().then(function (_title) {
title = _title;
});
return title === match;
}, 'Test page title, so we know page is loaded', testTimeout);
// test title is correct
runs(function () {
expect(title).toEqual(match);
});
});
});
waitsFor polls直到返回true结果,此时执行以下run()。对我来说似乎没什么特别的,特别是因为它进行了两次比较,一次是为了等待而另一次是为了茉莉花断言。
我做了另一个使用mocha而不是jasmine的例子,使用assert库,确实有这个问题。