标签: web-testing

测试生成的HTML代码的规范方法是什么?

我通常遵循的两种方法是:

  1. 将HTML转换为字符串,然后针对目标字符串对其进行测试.这种方法的问题在于它太脆弱了,并且会出现非常频繁的假阴性,比如说某些地方有额外的空白.

  2. 将HTML转换为字符串并将其作为XML解析,然后使用XPath查询在特定节点上进行断言.这种方法运行良好,但并非所有HTML都带有结束标记并解析它,因为在这种情况下XML失败.

这两种方法都有严重的缺陷.我想这种测试必须有一套完善的方法(或方法).它是什么?

html java testing unit-testing web-testing

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

如何在testcafe中调用外部异步等待功能

我有helper.js它的功能

async function getLink() {
  try {
    const message = await authorize(content);
    const link = message.match(/href=\"(.*?)\"/i);
    return link[1];
  }
  catch(error) {
    console.log('Error loading:',+error);
    throw(error);
  }
}
module.exports.getLink = getLink;
Run Code Online (Sandbox Code Playgroud)

我想在测试执行后在 testcafe 脚本中使用这个函数

在 test.spec.js 中

import { Selector } from 'testcafe';
let link = '';
fixture My fixture
.page `https://devexpress.github.io/testcafe/example/`;

 test('test1', async t => {

// do something with clientWidth
});
test('test2', async t => {
  // use the getLink function here from the helper.js to get the …
Run Code Online (Sandbox Code Playgroud)

javascript automated-tests web-testing e2e-testing testcafe

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

TestCafe Live没有运行

我在OsX上,使用节点10.1.5.3的nvm。Testscafe(不在线)工作正常,但我试图按照Testcafe-live上的说明进行操作

在解释如何在本地安装的步骤

如果您已经在本地将testcafe-live安装到项目中,请在package.json中添加一个npm脚本以运行测试:

它指的是package.json文件,我在脚本部分下添加了条目

   "scripts": {
    "test": "eslint ./**/*.js",
    "testcafe-live": "testcafe-live chrome tests/"
  },
Run Code Online (Sandbox Code Playgroud)

但是当我跑步时

npm运行testcafe-live

我得到这些错误:

npm ERR! path /Users/Thomas.Pavan/testcafe/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open '/Users/Thomas.Pavan/testcafe/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/Thomas.Pavan/.npm/_logs/2019-03-11T14_58_28_946Z-debug.log …
Run Code Online (Sandbox Code Playgroud)

automated-tests web-testing npm e2e-testing testcafe

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

选择器“ .exits”和“ .visible”之间的Testcafe差异

即使我已经阅读了TC提供的文档,但仍不确定之间有什么区别:

await t.expect(element.visible).ok();
Run Code Online (Sandbox Code Playgroud)

await t.expect(element.exists).ok();
Run Code Online (Sandbox Code Playgroud)

我有一种预感,以某种方式可见的包括存在检查,但是另一方面,元素可能存在,但是不在可见区域...

先感谢您

automated-tests web-testing typescript e2e-testing testcafe

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

我的应用程序代码如何知道应用程序是否正在使用 testcafe 进行测试?

我有一套使用 TestCafe 运行的测试。在一个组件中,我需要根据应用程序是否在 testcafe 中运行来了解是否向窗口公开一些数据,即

if (window.Testcafe === true) {
    window.property = data;
}
Run Code Online (Sandbox Code Playgroud)

这可以通过另一个测试框架 Cypress 来实现,它公开了 window.Cypress。我尝试在 testcafe 测试/装置中设置窗口属性,使用代码达到以下效果

test('Test 1', async t => {
    await t.eval(() => {window.Testcafe = true});
    const val = await t.eval(() => window.Testcafe);
    // val === true
})
// In component window.Testcafe is false
Run Code Online (Sandbox Code Playgroud)

我对其他方法持开放态度(除了窗口属性)。还有其他人做过类似的事情吗?

automated-tests web-testing reactjs e2e-testing testcafe

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

如何使用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
查看次数

如何根据另一个元素的文本单击一个元素

给定多行用户表...

<tr>
  <td class="cell--select">
    <input class="choice__input" type="checkbox">
  </td>
  <td>
    <div class="user">
      <ul class="user-info">
        <li class="name">Jane Doe</li>
      </ul>
    </div>
  </td>
</tr><tr>
...
Run Code Online (Sandbox Code Playgroud)

我想选择具有给定用户名的行,然后单击该行上的复选框。我尝试了多种方法来做到这一点,包括withText和/或parent()和/或find()等...,但没有任何效果。

通常,我会抓住所有的li.names,检查正确的名称,然后使用索引来检查正确的复选框,但是我也想不出一种方法来实现。

卡住...想法?

automated-tests web-testing selector e2e-testing testcafe

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

将ReactSelector用于TestCafe时,不断获取`ReExecutablePromise {_then:[],_fn:[Function],_taskPromise:null}

我正在尝试使用TestCafe在React网站上实施测试。我想使用getReact()打印各种道具/属性。但是,当打印到控制台时,我总是得到ReExecutablePromise { _then: [], _fn: [Function], _taskPromise: null }

这是我的代码:

var sideBar = ReactSelector('Sidebar').getReact();
console.log(sideBar);
Run Code Online (Sandbox Code Playgroud)

我还尝试获取实际属性:

sideBarprops = checkListPage.sideBar.getReact(({ props }) => props.isChecklistVisible);
console.log(sideBar);
Run Code Online (Sandbox Code Playgroud)

任一项总是打印 ReExecutablePromise { _then: [], _fn: [Function], _taskPromise: null }

我需要能够打印ReactSelector的属性,类名,状态,键等的实际值。

automated-tests web-testing reactjs e2e-testing testcafe

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

模拟API以根据请求URL的动态部分给出响应

我想模拟API调用,以便请求 http://localhost:8080/api/test/<yyyy-mm-dd> 进行响应: {date: <yyyy-mm-dd>, data: 'my cool data'} 这里<yyyy-mm-dd>是不固定的(此请求最近7天进行7次)

如何在TestCafé中为此创建模拟?请注意,响应数据取决于请求URL。

automated-tests web-testing httprequest e2e-testing testcafe

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

包含 2 个或更多“OR”条件的 XPath 不起作用?

有一个锚标记,用户可以更改其值。现在,我想编写一个 Xpath 查询,在一个语句本身中搜索多个链接文本名称。

<a href="#login" class="fancybox" xpath="1">Signin</a>
Run Code Online (Sandbox Code Playgroud)

现在,可以通过用户配置文件更改链接文本值。例如,“登录”、“登录”、“单击此处登录”或“立即登录”

如果我写 xpath:-

//a[contains(text(),'Login') or contains(text(),'Log-in') or contains(text(),'Login now') or contains(text(),'click here to Login')]
Run Code Online (Sandbox Code Playgroud)

然后它失败了。我需要使用 Selenium 单击此元素。

请帮忙。

html xml anchor xpath web-testing

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