单击复选框后,我的应用程序将触发 GET 请求。
我正在尝试用 cypress 验证这一点,但它会抛出 ' Timed out retrying after 30000ms: cy.wait() timed out waiting 30000ms for the 1st request to the route: getGridWind10M. No request ever occurred.'
我的代码:
cy.intercept("GET", "v1/kml/F20210903120000/Wind10M?view=grid*").as('getGridWind10M');
cy.get('[data-test="ckbx-w10m"]')
.check({ force: true })
.should("be.checked");
cy.wait('@getGridWind10M').its('response.statusCode').should('eq', 200)
Run Code Online (Sandbox Code Playgroud)
实际端点:
https://domain/path/api/v1/kml/F20210903120000/Wind50M?view=grid&time=2021-09-03T14:00:00.000Z&z=3&x=5&y=4
Run Code Online (Sandbox Code Playgroud)
测试日志:
我尝试过以下方法,但没有成功。有人请帮助我找出我在这里缺少的位置和内容,因为请求已成功完成,如图所示?
cy.intercept("GET", "*/F20210903120000/Wind10M?view=grid*").as('getGridWind10M');
cy.intercept("GET", "*F20210903120000/Wind10M?view=grid&*").as('getGridWind10M');
cy.intercept("GET", "*F20210903120000/Wind10M?view=grid*").as('getGridWind10M');
cy.intercept("GET", "/F20210903120000/Wind10M?view=grid*").as('getGridWind10M');
Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我有一个流程触发两个 POST 请求到相同的端点,但请求正文略有变化。我们如何使用 cypress 来实现这一目标?
请求1:
请求网址:http://localhost:8000/weather/F20210908060000/spot
请求方式:POST
请求正文:
{
"locations": [
{
"timestamp": "2021-09-18T06:00:00.000Z",
"coordinates": [
106.41364531249987,
-15.435157996299878
]
},
{
"timestamp": "2021-09-18T07:00:00.000Z",
"coordinates": [
106.41364531249987,
-15.435157996299878
]
}
],
"elements": [
2
]
}
Run Code Online (Sandbox Code Playgroud)
请求2: 请求URL:
http://localhost:8000/weather/F20210908060000/spot
Run Code Online (Sandbox Code Playgroud)
请求方式:POST
请求正文:
{
"locations": [
{
"timestamp": "2021-09-18T04:00:00.000Z",
"coordinates": [
106.41364531249987,
-15.435157996299878
]
},
{
"timestamp": "2021-09-18T05:00:00.000Z",
"coordinates": [
106.41364531249987,
-15.435157996299878
]
},
{
"timestamp": "2021-09-18T06:00:00.000Z",
"coordinates": [
106.41364531249987,
-15.435157996299878
]
},
{
"timestamp": "2021-09-18T07:00:00.000Z",
"coordinates": [
106.41364531249987, …Run Code Online (Sandbox Code Playgroud) 尝试单击基于具有启用/禁用状态的另一个元素的按钮。由于某种原因,我禁用的检查代码不起作用,并且它总是以另一个语句结束(“找不到现有路由”),即使 UI 启用了选择按钮。
cy.get('voyage-suggested-routes')
.find('button.selectButton')
.then(($routes) => {
if ($routes.is(":disabled")) {
cy.log("No existing routes found...")
} else {
cy.log("Deleting......")
cy.get('.delete-button').click({ force: true, multiple: true })
}
});
Run Code Online (Sandbox Code Playgroud)
这是 DOM:(默认有 3 个元素,如果未禁用,每个选择按钮都会有一个删除选项。)
<button class="selectButton" disabled route="1">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="..."></path></svg>
SELECT
</button>
Run Code Online (Sandbox Code Playgroud)
也尝试了 jquery 方法,但结果相同。
var btnStatus = Cypress.$('.selectButton')
.is(":disabled");
if (btnStatus == true) {
cy.log("Deleting......")
cy.get('.delete-button').click({ force: true, multiple: true })
} else {
cy.log("No existing routes found...")
}
Run Code Online (Sandbox Code Playgroud)
我缺少什么?
更新1: Electron输入后,我的新代码是:
cy.get('voyage-suggested-routes')
.find('button.selectButton')
.then(($routes) => {
if ($routes.is(":disabled").length === 0) …Run Code Online (Sandbox Code Playgroud) 我有 2 个功能文件并尝试执行以下操作
特征 1:[calling.feature]
Feature: Test loop over by calling a feature file
Scenario Outline: Testing loop over feature file
* call read('called.feature') { argument = '<arg>' }
Examples:
|arg|
|"HELLO"|
|"WORLD"|
Run Code Online (Sandbox Code Playgroud)
特征 2:[被称为.特征]
Feature: Test loop over in Karate framework
Scenario Outline: Testing loop over feature
* def callingArg = arg
* match '<arg2>' == callingArg
Examples:
|arg2|
|"TEST1"|
|"WORLD"|
Run Code Online (Sandbox Code Playgroud)
当我使用 'Calling.feature' 中的 read 调用 'Called.feature' 时,我期望它会在两个功能文件中的所有示例中迭代使用
但是空手道在发现失败时退出,在这种情况下,当从 Calling.feature 传递参数“HELLO”时,它在“被调用的.特征”中的匹配步骤期间失败,例如“TEST1”,并且从不测试“WORLD”。
有没有办法可以强制空手道完成被调用的功能中的所有场景示例???
以下是日志:
calling: [com.intuit.karate.exception.KarateException: path: $, actual: 'HELLO', …Run Code Online (Sandbox Code Playgroud) // should store text in "person" variable
const person = cy.get(' div.global-user-nav-menu > div > div > div > div.info-container > div.display-name').text()
Run Code Online (Sandbox Code Playgroud)
我想使用这些“人”变量作为函数参数
SpaceView.assignTo(person)
Run Code Online (Sandbox Code Playgroud) 如何定位位于嵌套影子 DOM 内的搜索框?
到目前为止,我已经尝试了几种不同的方法来定位,下面是其中之一,但它不起作用:
定位器:
//Shadow roots
const SDW_MAINAPP_G1 = "main-app"
const SDW_VOYAGETOPBAR_G2A = "voyage-topbar"
const SDW_VOYAGEPANEL_G2B = "voyage-float-panel"
const SDW_VESSELLIST_G3B = "voyage-vessel-list"
const SDW_VOYAGEFILTER_G4B1 = "voyage-filter"
const SDW_LISTSORT_G4B2 = "voyage-vessel-list-sort"
//Left Panel - Search Box
const INP_SEARCH_VESSEL = "#filter"
Run Code Online (Sandbox Code Playgroud)
实际代码:
class SearchComponents {
static validateSearchBar() {
cy.get(SDW_MAINAPP_G1)
.shadow()
.find(SDW_VOYAGEPANEL_G2B)
.find(SDW_VESSELLIST_G3B)
.find(SDW_VOYAGEFILTER_G4B1)
.find(INP_SEARCH_VESSEL)
.should('be.visible')
.should('be.enabled')
}
//...
}
Run Code Online (Sandbox Code Playgroud)
在下面的 JSON 响应中,我需要为“nationalityDecription”为“USA”的记录提取“cid”。通过使用此查询作为参考,我在空手道功能文件中使用了以下 loc,但第一行本身因语法错误而失败(尝试了不同的组合)。现在,我使用自定义 javascript 作为一种工作正常的解决方法。我需要帮助来检查我是否在语法上遗漏了任何内容。谢谢
回复:
{
"header": {
"Id": "12345678",
"timeStamp": "2018-09-17T10:09:812.000"
},
"dataRecords": [
{
"cid": "31H678",
"cidMeta": "00",
"nationalityDecription": "CHINA"
},
{
"cid": "31S421",
"cidMeta": "01",
"nationalityDecription": "USA"
}
]
}
Run Code Online (Sandbox Code Playgroud)
特征文件:
* def record= $response.dataRecords[?(@.nationalityDecription=='USA')]
* def cid = record.cid
Run Code Online (Sandbox Code Playgroud) 我已经配置了以下 yml 文件,该文件可以启动每个节点的多个实例,并且所有节点都可以正确启动。
version: "3"
services:
selenium-event-bus:
image: selenium/event-bus:4.0.0-rc-1-prerelease-20210804
container_name: selenium-event-bus
ports:
- "4442:4442"
- "4443:4443"
- "5557:5557"
selenium-sessions:
image: selenium/sessions:4.0.0-rc-1-prerelease-20210804
container_name: selenium-sessions
ports:
- "5556:5556"
depends_on:
- selenium-event-bus
environment:
- SE_EVENT_BUS_HOST=selenium-event-bus
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
selenium-session-queue:
image: selenium/session-queue:4.0.0-rc-1-prerelease-20210804
container_name: selenium-session-queue
ports:
- "5559:5559"
depends_on:
- selenium-event-bus
environment:
- SE_EVENT_BUS_HOST=selenium-event-bus
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
selenium-distributor:
image: selenium/distributor:4.0.0-rc-1-prerelease-20210804
container_name: selenium-distributor
ports:
- "5553:5553"
depends_on:
- selenium-event-bus
- selenium-sessions
- selenium-session-queue
environment:
- SE_EVENT_BUS_HOST=selenium-event-bus
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
- SE_SESSIONS_MAP_HOST=selenium-sessions
- SE_SESSIONS_MAP_PORT=5556 …Run Code Online (Sandbox Code Playgroud) 我有以下方法utils.js
/**
* To verify the any array of objevt with given keyword
* @param {*} list
* @param {*} searchKeyword
* @returns true if any mismatch found and vice versa
*/
export const verifyMatchedItems = (list, searchKeyword) => {
var matchedItems = {
title: [],
region: [],
country: [],
};
var nonMatchedItems = [];
list.map((item, index) => {
if (item.title.includes(searchKeyword)) {
matchedItems.title.push(item.title);
} else if (item.region.includes(searchKeyword)) {
matchedItems.region.push(item.region);
} else if (item.country.includes(searchKeyword)) {
matchedItems.country.push(item.country);
} else {
nonMatchedItems.push(item); …Run Code Online (Sandbox Code Playgroud)