Selenium 自动重复夜间观察测试

Selenium 自动重复夜间观察测试,selenium,nightwatch.js,Selenium,Nightwatch.js,有人知道我可以自动重新运行一个设定次数的夜间监视测试的方法吗 我有以下代码: module.exports = { 'Log into system - create order': function (client) { client .url('XXXX') .waitForElementVisible('body', 1000) .assert.title('Reach - Log in') .assert.visible('#U

有人知道我可以自动重新运行一个设定次数的夜间监视测试的方法吗

我有以下代码:

module.exports = {
  'Log into system - create order': function (client) {
    client
      .url('XXXX')
      .waitForElementVisible('body', 1000)
      .assert.title('Reach - Log in')
      .assert.visible('#UserName')
      .setValue('#UserName', 'XXXX')
      .assert.visible('#Password')
      .setValue('#Password', 'XXXX')
      .assert.visible('input[value="Login"]')
      .click('input[value="Login"]')
      .waitForElementVisible('img.test', 1000)
      .assert.visible('li[title="XXXX"] a[tabindex="5"]')
      .click('li[title="Sales"]')
      .assert.cssClassPresent('li[title="XXXX"]', 'active')
      .click('a[href="/Quotes/Add"]')
      .waitForElementVisible('#s2id_CustomerId_Remote', 1000)
      .click('#s2id_CustomerId_Remote')
      .assert.visible('#s2id_autogen2_search')
      .setValue('#s2id_autogen2_search', 'bik')
      .waitForElementVisible('.select2-highlighted', 1000)
      .click('.select2-highlighted')
      .waitForElementVisible('#customerNotes', 1000)
      .click('#s2id_ProductId_Remote')
      .assert.visible('#s2id_autogen3_search')
      .setValue('#s2id_autogen3_search', '123XP')
      .pause(5000)
      .assert.visible('.select2-highlighted')
      .click('.select2-highlighted')
      .pause(5000)
      .assert.visible('.ui-sortable > tr')
      .setValue('#Quote_PONumber', 'abc123')
      .click('input[value="Create Order"]')
      .waitForElementVisible('.ac-order-number', 1000)
      .assert.visible('a[data-value="abc123"]')
      .pause(5000)
      .end()
  }
}
而不是
.end()
测试我想
。重新运行()
测试说30次。我在文档中找不到这样做的选项


非常感谢。

您可以将命令包装在
客户端中。perform()
和for循环中

client.perform(function(){
    for (i = 0; i < 29; i++) { 
      client
        .url('XXXX')
        .
        .
        .
        .end();
    }
})
client.perform(函数(){
对于(i=0;i<29;i++){
客户
.url('XXXX')
.
.
.
.end();
}
})

您可以将命令包装在
客户端中。perform()
和for循环中

client.perform(function(){
    for (i = 0; i < 29; i++) { 
      client
        .url('XXXX')
        .
        .
        .
        .end();
    }
})
client.perform(函数(){
对于(i=0;i<29;i++){
客户
.url('XXXX')
.
.
.
.end();
}
})

您需要的是一点异步迭代逻辑和
客户端。perform()
函数:

module.exports = {
  'Log into system - create order': function (client) {
    var currentIteration = 0,
        iterationCount = 30;

    function runTest() {
      client
        .url('XXXX')

        // ... YOUR CODE HERE, WITHOUT .end()

        .perform(function() {
          if (++currentIteration < iterationCount) {
            return runTest();
          }

          client.end(); // After passing 30 iterations end the session
        });
    }

    runTest();
  }
};
module.exports={
“登录系统-创建订单”:函数(客户端){
var currentIteration=0,
迭代计数=30;
函数runTest(){
客户
.url('XXXX')
//…此处是您的代码,没有.end()
.perform(函数){
if(++currentIteration
您需要的是一点异步迭代逻辑和
客户端。perform()
函数:

module.exports = {
  'Log into system - create order': function (client) {
    var currentIteration = 0,
        iterationCount = 30;

    function runTest() {
      client
        .url('XXXX')

        // ... YOUR CODE HERE, WITHOUT .end()

        .perform(function() {
          if (++currentIteration < iterationCount) {
            return runTest();
          }

          client.end(); // After passing 30 iterations end the session
        });
    }

    runTest();
  }
};
module.exports={
“登录系统-创建订单”:函数(客户端){
var currentIteration=0,
迭代计数=30;
函数runTest(){
客户
.url('XXXX')
//…此处是您的代码,没有.end()
.perform(函数){
if(++currentIteration
如果要使用不同的输入重复测试?然后你可以做这样的事情

module.exports = {
  "Login Fail Cases": function(browser) {
    let dataSet = [
      { username: "madhus", pass: "madhus" },
      { username: "admin", pass: "admin" }
    ];

   //will run for 2 times as length of dataset is 2
    dataSet.forEach(function(data) {
      browser
        .url("https://localhost:3000/")
        // you tests here
    }, this);

    // note: end the test outside the loop once all tests are executed
    browser.end();
  }
};

如果你想用不同的输入重复测试?然后你可以做这样的事情

module.exports = {
  "Login Fail Cases": function(browser) {
    let dataSet = [
      { username: "madhus", pass: "madhus" },
      { username: "admin", pass: "admin" }
    ];

   //will run for 2 times as length of dataset is 2
    dataSet.forEach(function(data) {
      browser
        .url("https://localhost:3000/")
        // you tests here
    }, this);

    // note: end the test outside the loop once all tests are executed
    browser.end();
  }
};

@akm您可以建议改进现有答案,而不是发布同一答案的不同迭代。@StratosIon恕我直言,您提供的代码与我的示例完全不同,而且根本不起作用,因为您尝试在异步上同步迭代code@akm除非你在本地试用过,而我正在做其他有效的事情,否则你怎么能证明你的说法是正确的?@StratosIon试着运行它
.end()
调用将在第一次迭代后结束会话。另外,在您的情况下,
client.perform()
是多余的,因为您可以将for循环放在测试方法主体中。关于循环,如果出于某种原因,在测试期间需要当前迭代的索引,那么它总是28,但是,为了解决这个问题,您可以将
let
放在
i
声明之前。@akm您可以建议对现有答案进行改进,而不是发布相同的不同迭代。@StratosIon恕我直言,您提供的代码与我的示例完全不同,而且根本不起作用,因为您尝试在异步上同步迭代code@akm除非你在本地试用过,而我正在做其他有效的事情,否则你怎么能证明你的说法是正确的?@StratosIon试着运行它
.end()
调用将在第一次迭代后结束会话。另外,在您的情况下,
client.perform()
是多余的,因为您可以将for循环放在测试方法主体中。关于循环,如果出于某种原因,您在测试期间需要当前迭代的索引,它将始终是28,但是为了修复这个问题,您可以将
let
放在
i
声明之前。