为 Nightwatch.js 测试重用 Selenium WebDriver 的浏览器会话 [英] Reuse the browser session for Selenium WebDriver for Nightwatch.js tests

查看:17
本文介绍了为 Nightwatch.js 测试重用 Selenium WebDriver 的浏览器会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写多个测试(例如登录测试、登录测试后使用应用程序、注销测试等),并且需要将它们全部放在单独的文件中.我遇到的问题是在每次测试之后,在下一个测试开始时,一个新的浏览器会话开始并且由于新会话而不再登录,所以我所有的测试都将失败,除了登录测试.

I need to write multiple tests (e.g. login test, use application once logged in tests, logout test, etc.) and need them all to be in separate files. The issue I run into is after each test, at the beginning of the next test being run, a new browser session start and it is no longer logged in due to the new session, so all my tests will fail except the login test.

那么,有没有一种方法可以使用相同的浏览器会话来按顺序运行我的所有测试,而不必复制我的登录代码?抱歉,如果这是一个转发,但我已经搜索和研究并没有找到任何答案.

So, is there a way to use the same browser session to run all of my tests sequentially without having to duplicate my login code? Sorry if this is a repost but I have searched and researched and not found any answers.

或者,有没有办法以某种方式链接测试文件?就像您运行的一个文件只调用所有其他测试文件一样?

OR, is there a way to chain the test files somehow? Like having one file that you run that just calls all the other test files?

推荐答案

使用此函数链接文件:

extend = function(target) {
    var sources = [].slice.call(arguments, 1);
    sources.forEach(function (source) {
        for (var prop in source) {
            target[prop] = source[prop];
        }
    });
    return target;
}

并像这样向这个主文件添加文件:

and adding files to this master file like this:

require("./testName.js");
module.exports = extend(module.exports,testName);

测试文件如下所示:

testName = {
    "Test" : function(browser) {

        browser
            // Your test code
    }
};

允许我拥有一个可以将所有测试链接到的文件,并始终保持相同的浏览器会话.它按照您在主文件中要求的顺序运行测试,如果您在最后一个测试完成之前不调用 browser.end(),它将使用一个浏览器窗口进行所有测试.

allowed me to have one file that could link all the tests to, and keep the same browser session the entire time. It runs the tests in the order you require them in the master file and if you do not call browser.end() until the last test is finished it will use one browser window for all tests.

这篇关于为 Nightwatch.js 测试重用 Selenium WebDriver 的浏览器会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆