Protractor - 如何在 Jasmine 上使用标签进行端到端测试

Protractor - How to use tags on Jasmine for e2e testning

我遇到了一些问题,我不知道该怎么做才能标记我想要的不同测试 运行。

我想要的测试只需要在我希望能够标记我想支付的付款是万事达卡、维萨卡或美国运通卡的最后。我确实有一个测试详细信息页面,例如编写用户信息,选择装运但最后我确实有多个选项我想测试待定我想测试的内容:

paymentPage.js

describe('Payment page', function () {
    paymentPage = new PaymentPage();

    // The details page is accessible by the specified URL
    it(`Credit Card - Has a form that can receive user data`, async function () {

        await paymentPage.creditCardPayment();

    });


     //Visa
    it('Enets payment', async function () {
            //TODO

    });

     //Amex
    it('Enets payment', async function () {
            //TODO

    });
});

如您所见,我想测试 3 个选项,所以每当我这样做时 "protractor e2e run mastercard" 这意味着它应该 运行 第一个测试用例,如果我选择 visa 然后做第二个测试用例,基本上跳过其余部分。

然而,我确实有几个测试在进入支付页面之前执行,但它们都需要为每次支付做同样的事情,所以这意味着支付前的所有测试用例每次都需要做完全相同的事情(所以我猜猜我们只需要在付款处做标签让脚本知道选择哪种付款)?

我怎样才能做一些标记或者也许有人有其他更好的解决方案?我可以选择我想要的支付提供商 运行

编辑:

exports.config = {

    capabilities: {
        browserName: 'chrome',
        chromeOptions: {
            args: [
                'incognito', 'disable-extensions', 'start-maximized', 'disable-infobars', '--window-size=1920,1080'
            ]
        },
        loggingPrefs: { browser: 'ALL' },
        platform: 'ANY',
        version: ''
    },


    specs: [
        'pagesDesktop/testPage.js',
        'pagesDesktop/paymentPage.js'
    ],

    jasmineNodeOpts: {
        reporter: "mochawesome",
        defaultTimeoutInterval: 60000
    },

    SELENIUM_PROMISE_MANAGER: false,

    framework: 'jasmine',

    params: {
        cardType: {
        }
    }

};

describe('Payment page', function () {
    paymentPage = new PaymentPage();

    console.log(browser.params.cardType);

    if (browser.params.cardType === "mastercard") {
        // The details page is accessible by the specified URL
        it(`Credit Card - Has a form that can receive user data`, async function () {
            await paymentPage.creditCardPayment();
        });
    }

只需添加if/else逻辑

describe('Payment page', function () {
    paymentPage = new PaymentPage();

    // The details page is accessible by the specified URL
    it(`Credit Card - Has a form that can receive user data`, async function () {

        await paymentPage.creditCardPayment();

    });


  if (browser.params.cardType === 'visa') {
    it('Enets payment', async function () {
            //TODO

    });
  } else if (browser.params.cardType === 'amex') {
     //Amex
    it('Enets payment', async function () {
            //TODO

    });
  }
});

您可以在此处 How can I use command line arguments in Angularjs Protractor? 或此处阅读如何参数化 teste https://medium.com/@nicklee1/making-your-protractor-tests-data-driven-e3c9e2a5e4e7