0

我有一个使用此代码设置的 nightwatchjs 项目。

module.exports = {
    beforeEach: browser => {

        // Starts a new session for each test
        browser.refresh();
    },
    before: async browser => {

        // Get the encrypted token
        const { token } = await authorizeUser({ browser });

        // Create the Test Tool instance
        await initializeTestTool({
            browser,
            channelOriginId: CHANNEL_ORIGIN_ID,
            token,
        });
    },
    ...allTests.reduce((acc, test) => ({ ...acc, ...require(test) }), {})
};

...allTests.reduce部分正在向对象添加更多测试。这是运行的第一个测试。

module.exports = {
    'Verify Level 1 Taxonomies are Showing': browser => {

        // Specify the selector mode before using any selectors since the previous test could have changed the mode
        browser.useCss();

        // Wait for the frame to load
        browser.waitForElementVisible('iframe', RESPONSE_WAIT_TIME * 3);

        // Switch context to the iframe
        browser.frame(0);

        // Change selector mode to XPath. XPath allows selectors with text matching logic
        browser.useXpath();
        const qr0 = "//span[contains(text(), 'Something else')]";

        // Wait for the quick reply to be shown
        browser.waitForElementVisible(qr0, RESPONSE_WAIT_TIME);

        // Click the quick reply
        browser.click(qr0);
        const taxonomyResponse = `//div[contains(text(), '${l1TaxonomyResponse}')]`;

        // Make sure the chat bot gives the expected response
        browser.waitForElementVisible(taxonomyResponse, RESPONSE_WAIT_TIME);

        // Make sure all the level 1 taxonomy quick replies are displayed
        for (const quickReply of l1QuickReplies) {
            const quickReplyText = `//span[contains(text(), '${quickReply}')]`
            browser.waitForElementVisible(quickReplyText, RESPONSE_WAIT_TIME);
        }
    },
};

我正在使用此脚本开始测试nightwatch automation.test.js -e chrome

before我遇到的问题是第一个测试在钩子完成之前开始运行。如果完成时间过长,则第一个测试在等待显示元素时会失败。 browser.waitForElementVisible('iframe', RESPONSE_WAIT_TIME * 3);

如何强制 nightwatchjsbefore在运行自动化测试之前等待钩子完成?

4

0 回答 0