尝试 ajax 请求时断开连接。柏
我对自动化测试还很陌生(直到最近我还是一名手动测试员),最近我开始使用 Cypress。
我一直在尝试从下拉列表中选择一个项目。选择一项后,下一个下拉列表应该出现在下面。应发出“POST”请求(如下面的 gif 所示)。
从第一个项目中选择一个项目后在赛普拉斯中运行此测试用例时下拉列表 我收到一条以我的母语显示的关于暂时缺少互联网连接且未发出“POST”请求的警报。
下面我提供了一个代码片段:
cy.intercept('POST', 'https://sprzedajemy.pl/new-offer-manager/ajax-get-category-selectors-box/tmp_id/-1647426073?category_id=id_2').as('authenticate')
cy.get(".theButton.theButtonRed.theButtonAdd").click({ force: true });
cy.pause();
cy.get("#category_selector_5>:nth-child(" + id + ")").then(function ($elem) {
cy.get("#category_selector_5").select($elem.text(),{ force: true });
cy.wait('@authenticate').its('response.statusCode').should('eq', 200)
});
错误消息,它是波兰语,基本上意味着:“没有互联网连接。请稍后重试。对于给您带来的不便,我们深表歉意
提前非常感谢。
I am quite new to automated testing (up until recently I'v been a manual tester) and I've recently taken up Cypress.
I've been trying to select an item from a drop down list. After selecting one item the next drop-down list should occur under. A 'POST' request should be made (as in the gif bellow).
browser behaviour during manual testing
When this test case is runned in Cypress after selecting an item from the first drop-down list I am getting an alert in my native language about a temporary lack of internet connection and no 'POST' request is being made.
Below I provide a code snippet:
cy.intercept('POST', 'https://sprzedajemy.pl/new-offer-manager/ajax-get-category-selectors-box/tmp_id/-1647426073?category_id=id_2').as('authenticate')
cy.get(".theButton.theButtonRed.theButtonAdd").click({ force: true });
cy.pause();
cy.get("#category_selector_5>:nth-child(" + id + ")").then(function ($elem) {
cy.get("#category_selector_5").select($elem.text(),{ force: true });
cy.wait('@authenticate').its('response.statusCode').should('eq', 200)
});
network tab throughout the whole test case execution in Cypress
Many thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
匹配 url 有点像魔术,但我认为问题出在 POST url 的
-1647426073
部分。不确定是
-
还是该部分中缺少字母字符,但它破坏了匹配。但可以使用通配符使其正常工作。
我没有断开连接,所以也许这是另一个问题。
下面总结了有效和无效的
cy.intercept()
。为了方便起见,我使用较长形式的routeMatcher。一些注释
基本 URL
https://sprzedajemy.pl
由 Cypress 假定,因此您可以将其省略*
通配符必须替换整个段(之间的部分>\
和?
),所以/*?category_id=id_2
但不是/*1647426073?category_id=id_2
您可以通过使用通配符来进一步缩短网址的开头,如下所示
**/tmp_id/*
pathname:
选项无需查询部分即可工作,或者您可以添加单独查询选项以进行更强的匹配您可以完全省略 URL 并添加
{times:1}
仅捕获单个 POST 请求。断言第二个下拉列表
如果您断言第二个下拉列表的内容,则无需等待 POST 拦截(除非您特别想检查它是否发生)
Matching urls is a bit of a black art, but I think the problem is the
-1647426073
portion of the POST url.Not sure if it's the
-
or the lack of alpha chars in that section, but it breaks the matching.But it can be wildcarded to make it work.
I'm not getting a disconnection, so maybe that's another issue.
The following summarizes working and not-working
cy.intercept()
. I'm using the longer form of routeMatcher for convenience.Some notes
the base url
https://sprzedajemy.pl
is assumed by Cypress so you can leave it outthe
*
wildcard must replace the whole segment (part between\
and?
), so/*?category_id=id_2
but not/*1647426073?category_id=id_2
you can shorten further by wildcarding the start of the url as per
**/tmp_id/*
pathname:
option works without the query portion, or you can add the query option separately to make a stronger matchyou can leave out the URL altogether and add a
{times:1}
to catch only that single POST request.Asserting the 2nd dropdown
If you assert the contents of the 2nd dropdown, there is no need to wait for the POST intercept (unless you specifically want to check it occurs)