小编Yul*_*lia的帖子

如何在testcafe脚本中添加检查xhr响应的递归函数?

我正在尝试编写一个测试下载作品,该作品需要检查xhr响应的状态是否为READY。我使用诺言在TestCafe中创建了一个客户端函数,但是在递归的情况下失败了。

我应该如何修复我的代码来处理这种情况?

PS为新手问题道歉,我刚刚开始自动化测试之旅。


fixture`Download report works`


test
    .requestHooks(logger)//connected a request hook, will wait for logger request 
    ('I should be able to download PDF report from header of the page', async t => {
        //recursively check if response status is READY, and then go to assertions

        const waitForDownloadResponseStatus = ClientFunction((log) => {
            return new Promise((resolve,rejects)=>{
                const waitForStatus=()=>{

                        const arrayFromResponse = JSON.parse(log.response.body);
                        const responseStatus = arrayFromResponse.status;
                        if (responseStatus == 'READY')
                        {
                            resolve(responseStatus);
                        } 
                        else {
                            waitForStatus();
                        }
                    }
                waitForStatus();
                })
        });
        //page …
Run Code Online (Sandbox Code Playgroud)

javascript automated-tests web-testing e2e-testing testcafe

6
推荐指数
1
解决办法
131
查看次数

如何使用TestCafe访问应用程序操作?

我试图寻找答案,但找不到。我想编写一个函数来删除以前使用的测试组织,然后再在testcafe中开始测试。

如果要通过UI进行操作,这将是一个非常耗时的操作。因此,我想知道是否可以使用应用程序操作并编写一个函数删除我的测试数据?

我的想法是执行以下步骤:1.找到要删除的所有测试组织2.遍历每个测试组织,调用ShowDeleteOrgModal()方法,然后再调用DeleteOrganisation()方法。

我看到其他测试工具使用window()提供对应用程序操作的访问。有什么办法可以在testCafe中实现它?

按钮选择器如下所示。

<button class="button_class" onclick="OurApplicationName.ShowDeleteOrgModal('organisation_id');
return false;">Delete Organisation</button>
Run Code Online (Sandbox Code Playgroud)

我们以这种方式在柏树中实现了类似的想法:

CleanUpOrgs() {
         cy.window().then((win) => {
         let numberOfOrgs = win.window.$('tr:contains(' + Cypress.env('testOrgName') + ')').length;
            while (numberOfOrgs > 0) {
                cy.get('table').contains('tr', Cypress.env('testOrgName')).then(elem => {
                    let orgId = elem[0].id.replace('OurApplicationName_', '');
                    cy.window().then((win) => {
                        win.window.OurApplicationName.ShowDeleteOrgModal(orgId);
                        win.window.OurApplicationName.DeleteOrganisation();
                        cy.wait(2000);
                    });
                });
                numberOfOrgs--;
            }
        });
    },
Run Code Online (Sandbox Code Playgroud)

如何使用TestCafe访问窗口?

javascript automated-tests web-testing e2e-testing testcafe

2
推荐指数
1
解决办法
138
查看次数