我有一个任务是使用Jest测试 gRPC 客户端调用功能。典型的 Node.js 函数如下所示:
client.authenticate(request, meta, (error, response) => {
if (!error) {
console.log('REPLY FROM SERVER: ', response)
} else {
console.error(error)
}
})
Run Code Online (Sandbox Code Playgroud)
过程调用是回调函数,正如我们所见,我无法将响应对象导出到外部变量。上面的函数是我需要测试的函数。我需要检查该函数是否已被正确调用。我该如何用玩笑来做到这一点?现在已经挣扎了一段时间了。
我不时使用量角器 1.7 中引入的“预期条件”功能。
用例:
var EC = protractor.ExpectedConditions;
browser.wait(EC.visibilityOf(header.displayName), 10000);
Run Code Online (Sandbox Code Playgroud)
哪里header是页面对象。
如果header.displayName在 10 秒内不可见,则会抛出错误:
[firefox #4] 2) Describe description here
[firefox #4] Message:
[firefox #4] Error: Wait timed out after 10082ms
[firefox #4] Stacktrace:
[firefox #4] Error: Wait timed out after 10082ms
[firefox #4] ==== async task ====
[firefox #4] at [object Object].<anonymous> (/Path/to/project/test/e2e/my.spec.js:38:17)
Run Code Online (Sandbox Code Playgroud)
这不是很可读,需要一些时间来理解和研究。
题:
是否可以自定义这种等待超时错误?
仅供参考,我们可以提供自定义expect失败消息,如下所述:
我写了一些komplex量角器测试,但一切都在一个文件中.我在它的顶部装载所有变量,如:
var userLogin = "John";
Run Code Online (Sandbox Code Playgroud)
然后在代码中的某个地方我一起使用它.
我需要做的是1.将所有变量文件分离到aditional文件(一些配置文件)2.每个测试到一个文件
1-我尝试使用config.js添加所有变量,我在protractor.conf.js中需要它正确加载问题是当我在某些测试中使用任何变量时它不起作用(测试失败,"userName is未定义")我知道有一种方法可以在每个测试脚本中查询config.file,但这在我看来并不是最好的选择.
2-如果它是独立的,我怎么知道我在最后一个脚本中做了什么,例如如何知道我已经登录?
谢谢.
我与量角器打架,因为对于一些测试我需要UPLOAD文件.我的HTML看起来像:
<div class="panel-footer">
<ul class="list-unstyled">
<!-- ngRepeat: file in imagesToUpload -->
</ul>
<button class="btn btn-sm btn-success pull-right ng-binding ng-hide" ng-show="imagesToUpload.length" ng-click="uploadImages()">Nahrát na server</button>
<button class="btn btn-sm btn-primary ng-binding" ng-file-select="onImageSelect($files)" data-multiple="true" style="overflow: hidden;">Vybrat soubory<input type="file" class="btn btn-sm btn-primary ng-binding" ng-file-select="onImageSelect($files)" data-multiple="true" multiple="multiple" __wrapper_for_parent_="true" style="width: 1px; height: 1px; opacity: 0; position: absolute; padding: 0px; margin: 0px; overflow: hidden;"></button>
</div>
Run Code Online (Sandbox Code Playgroud)
输入HTML:
<input type="file" class="btn btn-sm btn-primary ng-binding" ng-file-select="onImageSelect($files)" data-multiple="true" multiple="multiple" __wrapper_for_parent_="true" style="width: 1px; height: 1px; opacity: 0; position: absolute; padding: 0px; margin: 0px; …Run Code Online (Sandbox Code Playgroud) 我是量角器的新手.我已经为第一个用户登录应用程序编写了一个角度测试,然后单击特定按钮来计算一个数字.有时它有效,有时不行!
这是代码:
describe('Protractor Demo App', function () {
it('should login to app', function () {
browser.get('http://localhost:8080/main');
var userName = element(by.id('username'));
var passWord = element(by.id('pwd'));
var loginBtn = element(by.id('loginBtn'));
userName.sendKeys('user');
passWord.sendKeys('1');
loginBtn.click();
expect(browser.getCurrentUrl()).toEqual('http://localhost:8080/main/#/intro');
});
it('should calculate something', function () {
browser.get('http://localhost:8080/main/#/something');
var next = element(by.css('[ng-click="calculate()"]'));
element(by.model('accountNo')).sendKeys('0293949223008');
next.click();
expect(element(by.binding('result')).getText()).toEqual('55017000000029');
});
it('should show error for invalid input no', function () {
browser.get('http://localhost:8080/main/#/something');
var next = element(by.css('[ng-click="calculate()"]'));
element(by.model('accountNo')).sendKeys('9999456123789');
next.click();
expect(element(by.css('[class="messageObject warning"]')).getText()).toEqual('message for invalid input');
});
});
Run Code Online (Sandbox Code Playgroud)
首先"它"总是有效,但第二和第三,有时是工作.碰巧只有一个人没有工作;
这是错误:
消息:失败:未知错误:元素...在点(1214,275)处不可点击.其他元素将收到点击:...(会话信息:chrome = 55.0.2883.87)(驱动程序信息:chromedriver = 2.26.436362(5476ec6bf7ccbada1734a0cdec7d570bb042aa30),平台= Windows …
我在Test Cafe Studios中创建了一个测试。我想让该测试每晚自动运行,而无需用户运行测试(打开程序,单击“开始”等),此软件是否可以实现?如果有一些解决此问题的示例,将很有帮助!我已经为一些非常基本的测试粘贴了一些代码,只是检查页面是否会打开。我已经用问题的一般信息填写了一些''
提前致谢。
Windows Task Scheduler
import { Selector } from 'testcafe';
fixture `svdemo`
.page `my website here `
.httpAuth({
username: 'username',
password: 'password',
domain: 'domain'
});
test('Visit Each Page', async t => {
await t
.click(Selector('span').withText('Page1'))
.click(Selector('a').withText('Homepage'))
.click(Selector('a').withText('Page2'))
.click(Selector('a').withText('Homepage'))
.click(Selector('a').withText('Page3'));
Run Code Online (Sandbox Code Playgroud)
});
我希望看到测试运行并每晚通过自己的测试。
javascript testing continuous-integration end-to-end testcafe
我想知道是否有人使用 Puppeteer-Cluster 可以详细说明 Cluster.Launch({settings}) 如何防止在不同上下文中的页面之间共享 cookie 和 Web 数据。
此处的浏览器上下文是否确实阻止了 cookie,并且不会共享或跟踪用户数据?Browserless' 现在臭名昭著的页面似乎认为不,这里和 .launch({}) 应该在任务上调用,而不是在队列之前。
所以我的问题是,我们如何知道 puppeteer-cluster 是否在排队任务之间共享 cookie/数据?图书馆中有哪些选项可以降低被贴上机器人标签的机会?
设置:我将 page.authenticate 与代理服务、随机用户代理一起使用,但偶尔仍会被我正在执行测试的站点阻止(403)。
async function run() {
// Create a cluster with 2 workers
const cluster = await Cluster.launch({
concurrency: Cluster.CONCURRENCY_BROWSER, //Cluster.CONCURRENCY_PAGE,
maxConcurrency: 2, //5, //25, //the number of chromes open
monitor: false, //true,
puppeteerOptions: {
executablePath,
args: [
"--proxy-server=pro.proxy.net:2222",
"--incognito",
"--disable-gpu",
"--disable-dev-shm-usage",
"--disable-setuid-sandbox",
"--no-first-run",
"--no-sandbox",
"--no-zygote"
],
headless: false,
sameDomainDelay: 1000,
retryDelay: 3000,
workerCreationDelay: 3000
}
});
// …Run Code Online (Sandbox Code Playgroud) automated-tests end-to-end node.js puppeteer puppeteer-cluster
我有一个包含两个字段用户名和密码的表单。输入用户名后,下一个按钮被启用,一旦我点击它,它就会显示一个密码字段,一旦输入,它会再次启用下一个按钮。如何等待按钮在表单更新之间启用?
我尝试了以下方法,一种被评论,另一种没有。两者都不适合我。
(async () => {
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
await page.goto('http://localhost:9000/start#!');
await page.type('#login-form-un-field', 'xxxx')
// await page.waitForTarget('#default-next-btn:not([disabled])')
await page.$eval('#default-next-btn:not([disabled])', elem => elem.click());
// const btnNext = await page.$('#default-next-btn');
// btnNext.click();
await page.type('login-form-passcode', '1234');
await page.click('#default-next-btn');
await browser.close();
})();```
Thanks for the help in advance.
Edit: the button is always present on the page. It is just disabled while form entries are being validated.
Run Code Online (Sandbox Code Playgroud) 我的服务器在 Postman 中返回 JSON 响应,其形式如下:
{
"accountType": "CHECKING",
"message": "Your account is overdrawn",
"withdrawalCode": 'SZWW-2000-11-CD'
}
Run Code Online (Sandbox Code Playgroud)
我正在像这样使用 Cypress 发送请求,并尝试断言所有字段。这是我的尝试
cy.request({
method: 'POST',
url: 'http://users/bank-account/withdrawal',
body: {
name: "paul.king@asher-bank.com",
password: "test123"
},
failOnStatusCode:false
}).its('body')
.should('have.property', 'accountType', 'Checking')
.should('have.property', 'message','User with withdrawal ref: \'CCR-001-009-GG\' is overdrawn')
.should('have.property', 'withdrawalCode','SZWW-2000-11-CD')
})
Run Code Online (Sandbox Code Playgroud)
这 3 个属性中只允许第一个属性断言。其他2个是不允许的。我如何断言多个属性。
如果我们已经在进行E2E(端到端)测试,我们还需要编写单元测试吗?
考虑到我们正在进行端到端测试中的所有功能测试,两者的优缺点是什么?
在我的应用程序中,我需要在 cypress 中检查以下流程:
我尝试测试的第一件事很简单:
it('should display spinner during page load', () => {
cy.visit(myPageUrl);
cy.get(selectors.spinner).should('exist');
cy.get(selectors.spinner, { timeout: 5000 }).should('not.exist');
});
Run Code Online (Sandbox Code Playgroud)
然而,这会产生竞争条件。在 cypress 断言旋转器存在之前,页面可能会加载并且旋转器将消失。这是一个直观的解释:
这是我的预期: 预期结果
以下是实际可能发生的情况,这将导致测试失败: 可能的结果
因此,经过一番研究后,我尝试了以下方法来解决竞争条件:
it('should display spinner during page load', () => {
let sendResponse;
const trigger = new Promise((resolve) => {
sendResponse = resolve;
});
cy.intercept('GET', '/myRequiredPageData', (req) => {
return trigger.then(() => {
req.reply();
});
});
cy.visit(myPageUrl);
cy.get(selectors.spinner).should('exist').then(() => {
sendResponse();
cy.get(selectors.spinner, { timeout: 5000 }).should('not.exist');
});
});
Run Code Online (Sandbox Code Playgroud)
但是,现在我有时会收到此错误:
A …
end-to-end ×12
testing ×7
javascript ×5
protractor ×4
cypress ×2
jasmine ×2
node.js ×2
puppeteer ×2
selenium ×2
angularjs ×1
async-await ×1
jestjs ×1
karate ×1
mocha.js ×1
request ×1
spock ×1
testcafe ×1
unit-testing ×1