如何在一节中的元素上使用waitForElementVisible?

时间:2018-11-30 22:15:52

标签: nightwatch.js

我有以下页面对象:

const commands = {
  addAmount: function(value) {
    return this.waitForElementVisible("@amount", 2000).setValue(
      "@amount",
      value
    );
  },
  addCurrency: function(value) {
    return this.waitForElementVisible(".newCoin @currency", 2000)
      .click(`select[name=newcurrency] option[value='${value}']`);
  },
  addCoin: function() {}
};

module.exports = {
  commands: [commands],
  sections: {
    newCoin: {
      selector: "#add-new-coin",
      elements: {
        amount: {
          selector: "input[name=newamount]"
        },
        currency: {
          selector: "select[name=newcurrency]"
        },
        add: {
          selector: "button[name=addnewcoin]"
        }
      }
    }
  }
}; 

和测试实现:

module.exports = {
  "Add valid coin": function(client) {
    const user = client.globals.users.admin.user;
    const password = client.globals.users.admin.password;
    const auth = client.page.authentication();
    const newcoin = client.page.newcoin();
    const link = client.page.link();


client.url(client.launchUrl);

auth.login(user, password)
link.navigate("account");

newcoin.expect.section("@newCoin").to.be.visible;
newcoin.addCurrency("ETH");

client.end();

  }
};

运行我已经完成的测试:

FAILED:  1 assertions failed and 5 passed (4.325s)

 _________________________________________________

 TEST FAILURE:  1 assertions failed, 5 passed. (4.366s)

 ✖ 1_Account

   - Add valid coin (4.325s)
   Timed out while waiting for element <.newCoin @currency> to be present for 2000 milliseconds.  - expected "visible" but got: "not found"
       at Page.addCurrency (/home/developer/Desktop/elm/cockpit/UIT/pageobject/newcoin.js:11:17)
       at Object.Add valid coin (/home/developer/Desktop/elm/cockpit/UIT/tests/1_Account.js:18:13)

我在做什么错了?

0 个答案:

没有答案