自动e2etesting – WebDriverJS,茉莉花

我正在按照这个教程http://engineering.wingify.com/posts/e2e-testing-with-webdriverjs-jasmine/

第一部分要求创buildtestfile.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时,我能够运行浏览器

我创build了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 

预期的行为是启动浏览器,但这不是我所经历的。

您需要通过调用以下命令来增加超时值:

 jasmine.DEFAULT_TIMEOUT_INTERVAL = 9999999; 

看看这个例子的要点 (我在这里使用了WebdriverIO )。

试试jasmine-node --matchall testfile.jsjasmine-node testfile.spec.js ,默认情况下,jasmine-node在文件名中search包含“spec”的文件。

我有同样的事情。 driver.getTitle()是asynchronous的,因此Jasmine在任何返回之前完成。 我尝试了几个使用driver.wait()的东西,但无法获得asynchronous的权利。

最后我用Jasmine waitsFor – 等待一个真正的结果,或者它有自己的自定义超时。

我下面的例子稍微复杂一些,因为我加载谷歌,做一个search,然后检查结果的页面标题。

有了这个例子,你不需要设置全球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轮询,直到返回一个真实的结果,在这一点执行以下运行()。 对我来说,这似乎有点长久,尤其是两次比较,一次是为了等待,再次是为了茉莉花的断言。

我做了另一个例子,使用摩卡,而不是茉莉,使用断言库,确实有这个问题。