Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 自动化e2e测试-WebDriverJS,Jasmine_Node.js_Selenium_Angularjs E2e_Jasmine Node - Fatal编程技术网

Node.js 自动化e2e测试-WebDriverJS,Jasmine

Node.js 自动化e2e测试-WebDriverJS,Jasmine,node.js,selenium,angularjs-e2e,jasmine-node,Node.js,Selenium,Angularjs E2e,Jasmine Node,我正在学习这个教程 第一部分要求创建testfile.js var webdriver=require('selenium-webdriver') 当我运行node testfile.js时,我能够让浏览器运行 我创建testfile.js $cat testfile.js var webdriver = require('selenium-webdriver'); var driver = new webdriver.Builder(). withCapabilities(webd

我正在学习这个教程

第一部分要求创建testfile.js

var webdriver=require('selenium-webdriver')

当我运行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节点的地方

$ jasmine-node testfile.js 

Finished in 0 seconds
0 tests, 0 assertions, 0 failures, 0 skipped

预期的行为是它启动浏览器,但这不是我遇到的情况。

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

jasmine.DEFAULT_TIMEOUT_INTERVAL = 9999999;

看看(我在这里使用过)。

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

jasmine.DEFAULT_TIMEOUT_INTERVAL = 9999999;

看看(我在这里使用过)。

尝试
jasmine节点--匹配所有testfile.js
jasmine节点testfile.spec.js
,默认情况下,jasmine节点搜索文件名中包含“spec”的文件。

尝试
jasmine节点--匹配所有testfile.js
jasmine节点testfile.spec.js
,默认情况下,jasmine节点搜索文件名中包含“spec”的文件。

我也有同样的问题。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轮询直到返回真实结果,此时将执行以下runs()。这对我来说似乎有点冗长,尤其是当它做了两次比较时,一次是等待,一次是茉莉花的断言


我用mocha代替jasmine做了另一个例子,使用assert库,确实有这个问题。

我也有同样的问题。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轮询直到返回真实结果,此时将执行以下runs()。这对我来说似乎有点冗长,尤其是当它做了两次比较时,一次是等待,一次是茉莉花的断言


我用mocha而不是jasmine做了另一个例子,使用assert库,确实有这个问题。

Hi Will,如果你能给我指一些链接,提供web驱动程序/jasmine/selenium web UI测试的教程/api参考,那将非常有帮助。Hi Will,如果您能给我指出一些链接,提供web驱动程序/jasmine/selenium web UI测试的教程/api参考,这将非常有帮助。Wingify博客文章继续解释了为什么您需要添加
done
,因此您发布的代码示例不应该真正起作用。尽管如此,你还是应该看到一个浏览器正在启动。Wingify博客文章继续解释了为什么你需要添加
done
,因此你发布的代码示例实际上不应该工作。不过,您应该看到浏览器正在启动。