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

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

问题描述

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

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?

推荐答案

使用此功能将文件链接在一起:

Using this function to chain together 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);

并使测试文件如下所示:

and having the test file look like this:

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.

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

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