错误 ::: assertexpected { Object (content-security-policy, Expect-ct, ...) } 具有属性 text/plain;charset=ISO-8859-1
我尝试过下面的代码
describe("Assert header in response",function(){
beforeEach(function(){
cy.fixture("datainfixturefile").then(function(data){
this.data= data
var base=this.data.dcode
})
})
it.only('Valid Request',function(){
cy.request('POST',this.data.BaseURL+this.data.ValidReq).then((response) =>
{
expect(response).to.have.property('status',200);
expect(response.body).contains('APP-');
expect(response.headers).to.have.property("Content-Type", "text/plain;charset=ISO-8859-1");
})
})
Run Code Online (Sandbox Code Playgroud) 我得到以下代码,它循环遍历所有子项。我需要获取迭代次数,以便将其与子项总数进行比较。一旦循环处于最后一次迭代,就需要单击“下一步”按钮,以便打开新页面。
cy.get('[data-automation="AssetGrids_GridItemContainer_div"]').each(
($element, index) => {
cy.get('[data-automation="AssetGrids_GridItemContainer_div"]').then(
(listing) => {
const listingCount = Cypress.$(listing).length;
cy.log('Number of elements: ' + listingCount);
}
);
if (listingCount !=== index-1) {
// Do some magic here if it's not the last iteration
}
});
Run Code Online (Sandbox Code Playgroud)
我不确定这个解决方案是否正确,并且不会两次使用相同的定位器引发任何问题。有没有什么方法可以获取仅声明循环的找到元素的数量,以避免使用它?
cy.get('[data-automation="AssetGrids_GridItemContainer_div"]').then(
(listing) => {
const listingCount = Cypress.$(listing).length;
cy.log('Number of elements: ' + listingCount);
}
Run Code Online (Sandbox Code Playgroud) 示例代码-
describe('My Second Test Suite', function() {
it('My FirstTest case',function() {
cy.visit('https://www.google.com')
cy.url().should('be.equal', 'https://www.google.com');
})
})
Run Code Online (Sandbox Code Playgroud)
错误-断言https://www.google.com/等于https://www.google.com AssertionError 4000 毫秒后重试超时:预期 'https://www.google.com/' 等于 'https:// /www.google.com'
我试图断言当前 url 等于给定 url。
我希望获得关于扩展我的赛普拉斯测试工具的模式推荐。我有很多固定装置,而且很多固定装置都是相似的。因此,例如,我可能有一个规范,其中包含五个测试,测试五个固定装置,除了一条线外,这些固定装置都是相同的。这是不可扩展的。他们应该采用一个装置并使用参数来动态更新该线路。
我开始尝试使用与此类似的命令来打破一个装置:
Cypress.Commands.add('setDivisionsIds', (Array) => {
cy.intercept(
'GET',
`**/${Cypress.env('API_BASE_URL')}/v2/divisions/*`,
(req) => {
req.reply({ division
// ids: Array,
Run Code Online (Sandbox Code Playgroud)
其中该代码的最后一行是深度嵌套的 400 行 json 响应的第一行。
当我调用 `cy.setDivisionsIds(['1', '2']); 时
它确实会改变固定装置,现在我可以使用单个 ID 编写测试或使用超过 1 个 ID 的测试,并且它将返回该改变的拦截,而不是调用两个固定装置。
但是,将 400 行固定装置从固定装置文件夹移动到commands.ts 会堵塞我的commands.ts 并且不可扩展。我希望能够在此文件中轻松找到 cypress 命令并将灯具分开。其中一些固定装置也被 jest 使用,这就是为什么它们位于我的 /src 中的 /fixture 文件中,而不是位于 /cypress 中。
我正在考虑创建类似处理程序的东西,并将其保存为我的装置文件夹中名为 DivisionFixture.ts 的文件。(或者,我对夹具和处理程序之间的区别有点困惑。我认为处理程序是可以返回动态夹具的东西,而夹具文件应该用于单个夹具。)
但是,我不确定如何创建一个使用我的变异参数返回 json 对象的函数。IE。如果我尝试在 DivisionFixture.ts 中创建一个函数并像这样导出它
export function setDivision(Array) {
return [
external_ids: Array,
... rest of json
Run Code Online (Sandbox Code Playgroud)
我所有的 json 都带有下划线<key name> not found。我是否需要字符串化这个值以及如何在函数中做到这一点?或者我需要创建一个完整的类并将其导出吗?由于我的 json 文件的大小和嵌套(最多 10 倍),这很容易变得非常棘手。 …
我有一个 ag-grid,如链接 https://www.ag-grid.com/example/所示
此过滤器图标出现在银行余额之前
假设我没有任何其他选项,除了::before通过添加和删除过滤器值**出现和消失
<span class="ag-icon ag-icon-filter" unselectable="on" role="presentation">
::before
</span>
Run Code Online (Sandbox Code Playgroud)
**
那么我如何::before仅对关键字进行断言
我需要访问一个两次重定向到不同来源的 URL。例如:
域名-to-visit.com -> 重定向1.com -> 最终域名.com
下面的代码适用于单个重定向:
cy.origin('redirect1.com') => {
cy.visit('domain-to-visit.com');
});
Run Code Online (Sandbox Code Playgroud)
但我需要支持多个重定向。
我的本能反应是想将上面的代码包装在另一个代码中cy.origin,但尚不支持。
我如何访问domain-to-visit.com并允许其重定向到 Cypress 中的多个源?
我对我的服务器进行了调用(是对 ibm watson 的调用)进行一些操作,如果一切正常,则返回 200 响应。
这个调用的时间超过 5000ms,cypress 可以等待。我需要等到服务器返回响应,然后我知道我的反应应用程序中会出现一个弹出窗口。
这是我从后端对 Watson 的调用:
const launchWatsonTest = (watsonData) => {
const data = {
withCredentials: true,
mode: 'cors',
headers: {
'x-access-token': watsonData.token,
},
params: {
topicId: watsonData.corpusNameId,
workspaceId: watsonData.corpusArea
}
};
return clienteAxios.post(`test-watson`, watsonData, data);
};
Run Code Online (Sandbox Code Playgroud)
我该如何等待才能继续测试?
我对 cypress 进行了这个测试:
describe("E2E CognitiveTool", function() {
it("should crear respuesta simple sin problemas", function() {
cy.visit("http://localhost:3000");
cy.contains('[data-cy="topicName"]', 'CA2');
cy.get('[data-cy="accederResponsesCA2"]').click();
cy.get('[data-cy="crearResponse"]').should('exist')
.click();
cy.get('input[name="description"]')
.type('Simple Cypres Response');
cy.get('[name="typeResponse"]').first().check({force:true});
cy.get('[name="lateral_W"]').first().check({force:true});
cy.get('[name="rolViews"]').first().check({force:true});
cy.get('[name="workLoadLevel"]').first().check({force:true});
cy.get('[data-cy="continuar"]').click();
cy.get('input[id=0]')
.type('hola');
cy.get('input[id=1]')
.type('adios');
cy.get('input[id=2]') …Run Code Online (Sandbox Code Playgroud) 我只想在 Cypress 终端中记录消息,这样它们就不会出现在 Cypress 浏览器命令日志的屏幕截图中,而是可以在 CI 日志中查看。
我尝试使用Cypress.log(),但它将消息记录到终端和浏览器规范,这不是我想要的。这是我目前正在使用的,但它会用 RequestId 日志发送垃圾邮件屏幕截图(我只希望在 CI 终端中使用它)
beforeEach(() => {
cy.intercept({ url: API_HOST + '/api/**', middleware: true }, req => {
const requestId =
// Apollo lower cases the headers before sending the request
req.headers['x-request-id'] || req.headers['X-Request-Id'];
if (requestId) {
Cypress.log({
name: 'RequestID:',
message: requestId,
});
}
});
});
Run Code Online (Sandbox Code Playgroud)
我还尝试在 cy.intercept 中使用console.log(),但它仅记录到 Chrome 控制台而不是 Node.js 终端,因此消息不会显示在任何地方。(我注意到,如果我在其他地方的应用程序中使用 console.log ,它会将 console.log 添加到 Node.js 终端中,但特别是在 cy.intercept 中,它不会记录它)
最后,我尝试使用cy.task,
beforeEach(() => {
cy.intercept({ …Run Code Online (Sandbox Code Playgroud) 我需要一些帮助。
我有一个测试,我登录网站并选择状态。当我单击更新按钮时,模式将关闭,另一个模式将打开,并显示更新成功消息、确定按钮和 x 按钮。
我需要验证模式上的消息内容以及“确定”按钮是否有效,但由于此错误而无法使用
4000 毫秒后重试超时:预期“<button.btn.btn-success>”为“可见”
此元素 <button.btn.btn-success> 不可见,因为它具有 CSS 属性:position:fixed 并且它被另一个元素覆盖:
这是我使用的代码
cy.get('.modal-body > :nth-child(3) > .col-sm-9 > .form-
control').type('No Good Reason')
cy.get('.modal-body > :nth-child(4) > .col-sm-9 > .form-
control').type('Testing Memo')
cy.get('.btn-primary > .ng-scope').click()
//check the update ok modal appears correctly
cy.get('#updateSuccess').find(".modal-
title").contains('Update OK').should('exist')
cy.get('.modal-body').contains('Financial Account Status
Change (General) was updated OK').should('exist')
Run Code Online (Sandbox Code Playgroud)
这是元素和单击操作,我遇到了 cy.get('#updateSuccess').find('.btn').contains('OK').should('exist').click() 问题
这是 DOM
在此先感谢您的帮助
更新:好的,我能够使用存在检查模态上的元素,所以我更进一步了。我仍然无法单击“确定”按钮,因为该按钮被前一个模式上的元素覆盖
我正在尝试从以下网站上名为“国家/地区代码”的动态下拉列表中选择一个值 [此][1](已编辑)
默认情况下,此处显示一个值+1,其余值则隐藏。
首先我尝试了,cy.get('#country_code').select('+34')但没有成功。
然后我尝试了,cy.get('#country_code').eq(9).click()即使这样也行不通。
接下来我尝试cy.get('#country_code').contains('+34').click()这个也失败了。
还请给我有关如何选择菜单而不在字段中输入数据的建议。
这无助于我理解其实现背后的根本概念,因为我在静态下拉菜单中也遇到了类似的问题
我找不到处理此类问题的博客。
cypress ×10
javascript ×3
assertion ×1
cross-domain ×1
dropdown ×1
modal-dialog ×1
node.js ×1
react-redux ×1
redirect ×1
request ×1
typescript ×1
url ×1
vuetify.js ×1