我使用 Faker 模块来生成假的未来日期。我想要一个不久的将来的随机日期。
//Generate date
const dateOfTravel = faker.date.between('now', '2024/05/05').toLocaleDateString();
//Input date
cy.get("#date").type(`${dateOfTravel}`)
Run Code Online (Sandbox Code Playgroud)
页面字段需要日期的字符串格式为“YYYY/MM/DD”,但我得到“YYYY-DD-MM”
我如何将其隐藏到所需日期或者我需要不同的功能
是否可以通过上传文件来使用 cypress 测试 Web 服务(api)。我尝试使用 cy.request,但不知何故它无法识别该文件:
cy.fixture('exampleTsv.tsv').then((tsvExmp) => {
const blob = Cypress.Blob.binaryStringToBlob(tsvExmp, 'text');
// Cypress.Blob.binaryStringToBlob(tsvExmp).then((blob) => {
const formdata = new FormData();
formdata.append('file', blob, 'exampleTsv.tsv');
cy.request({
url: 'APi-URL',
method: 'POST',
auth: {
username: 'username',
password: 'password',
},
body: {
formdata,
},
headers: {
'content-type': 'binary',
},
}).as('details');
// Validate response code
cy.get('@details').its('status').should('eq', 204);
cy.get('@details').then((response) => {
cy.log(JSON.stringify(response.body));
});
});
Run Code Online (Sandbox Code Playgroud)
我只得到:状态:404 - 未找到。但 api-url 和文件正在工作(用邮递员测试:使用 [body->binary->tsvExmp.tsv])
我试图从元素调用文本/aria-标签,但我得到一个对象:
元素:
<p class="styles_startingColumn__8EIiq" data-cy="listValues_popup_txt" aria-label="1+" data-mui-internal-clone-element="true">1+</p>
Run Code Online (Sandbox Code Playgroud)
代码 :
getFirstValueInList() {
return cy.get("[data-cy='listValues_popup_txt']").should('be.visible').eq(0).invoke('attr','aria-label');
}
getFirstValueInList() {
return cy.get("[data-cy='listValues_popup_txt']").should('be.visible').eq(0).invoke('text');
}
Run Code Online (Sandbox Code Playgroud) 如何使用 data-testid 属性选择 css 定位器的第 n 个元素?我正在使用 cypress 但不能使用 eq([index]) 方法。(xpath 不是一个选项)
示例定位器,它是一个列表,我有多个带有 data-testid="frame" 的元素:
<div data-component="layout" data-testid="frame" class="tzhgczFPvds">TEST</div>
Run Code Online (Sandbox Code Playgroud)
我需要使用定位器(sourceitem、targetitem)的示例代码:
describe('Dragtest', () => {
it('should dragndrop', () => {
cy.visit('/yourpage')
cy.get('.sourceitem').drag('.targetitem', options)
})
})
Run Code Online (Sandbox Code Playgroud)
谢谢
这是我的问题:我有一个大表单,我想在其中执行 e2e 测试。当用户更改其字段中的值时,此表单会填充 URL 查询参数。
当我使用 Cypress 来检查它时,每次在表单中输入内容时,它都会生成大量日志(例如(新 URL)见下文),使得测试难以阅读。
http://localhost:3000/demande-immersion?email=&firstName=Archib&lastName=&phone=&financiaryHelp=&emergencyContact=&emergencyContactPhone=&birthdate=&agencyDepartment=86&siret=&businessName=&businessAdvantages=&etFirstName=&etLastName=&etJob=&etPhone=&etEmail=&erFirstName=&erLastName=&erPhone=&erEmail=&immersionAddress=&agencyId=1411b4b7-a7a8-4d69-92ac-1eca1ac75c50&immersionActivities=&immersionSkills=&sanitaryPreventionDescription=&workConditions=&dateStart=2023-04-27&dateEnd=2023-04-28&schedule=%7B%22totalHours%22%3A14%2C%22workedDays%22%3A2%2C%22isSimple%22%3Atrue%2C%22selectedIndex%22%3A0%2C%22complexSchedule%22%3A%5B%7B%22date%22%3A%222023-04-27T00%3A00%3A00.000Z%22%2C%22timePeriods%22%3A%5B%7B%22start%22%3A%2208%3A00%22%2C%22end%22%3A%2212%3A00%22%7D%2C%7B%22start%22%3A%2213%3A00%22%2C%22end%22%3A%2216%3A00%22%7D%5D%7D%2C%7B%22date%22%3A%222023-04-28T00%3A00%3A00.000Z%22%2C%22timePeriods%22%3A%5B%7B%22start%22%3A%2208%3A00%22%2C%22end%22%3A%2212%3A00%22%7D%2C%7B%22start%22%3A%2213%3A00%22%2C%22end%22%3A%2216%3A00%22%7D%5D%7D%5D%7D
Run Code Online (Sandbox Code Playgroud)
有没有办法过滤 Cypress 登录应用程序的事件(使用cypress open)?
我必须使用 Cypress 验证网页上不同元素上的特殊字符串。
\n特殊字符串是:T!@$^()-_+, &_-=tt.\xc3\x98 {y}[a] \xc2\xa3 fi
每当我尝试验证字符串时,我都会在 Cypress 中收到以下断言错误:
\nAssertionError Timed out retrying after 4000ms: Expected to find content: \'T!@$^()-+, &-=tt.\xc3\x98 {y}[a] \xc2\xa3 fi\' within the element: <label> but never did.
下面是代码块:
\n cy.visit(\'public/special-character.html\')\n \n cy.get(\'label\').contains(\'T!@$^()-_+, &_-=tt.\xc3\x98 {y}[a] \xc2\xa3 fi\');\n cy.get(\'p\').contains(\'T!@$^()-_+, &_-=tt.\xc3\x98 {y}[a] \xc2\xa3 fi\');\n \n })\nRun Code Online (Sandbox Code Playgroud)\n还附上了一个示例 HTML 页面:
\n cy.visit(\'public/special-character.html\')\n \n cy.get(\'label\').contains(\'T!@$^()-_+, &_-=tt.\xc3\x98 {y}[a] \xc2\xa3 fi\');\n cy.get(\'p\').contains(\'T!@$^()-_+, &_-=tt.\xc3\x98 {y}[a] \xc2\xa3 fi\');\n \n })\nRun Code Online (Sandbox Code Playgroud)\r\n我想使用https://www.npmjs.com/package/chalk作为控制台日志。
现在如果我使用console.log它就可以了
console.log(chalk.blue("Hello World"))
但是当我用 cy.task 运行它时,它不会给出任何错误,但不会显示任何着色
cy.task('log', chalk.blue("Hello World"));它打印 Hello World 但不是蓝色
我究竟做错了什么?
我想从一个网站跨域到另一个网站,cypress 让我可以使用 cy.origin() 函数很好地做到这一点。
我还想要的是将我所在页面的页面对象模型传递到此函数中。
我尝试了几种实例化我的类并根据文档传递到参数的方法。我无法让它在运行时执行...
const args = {
testObject: new MyPageObject()
};
// As the domain has changed we need to use the cy.origin function
cy.origin(dfBaseURL, {
args: {
args
}
}, ({
args
}) => {
args.testObject.getContinueButton().click({
force: true
});
})
Run Code Online (Sandbox Code Playgroud)
目前与...
我试图wait()在测试中避免使用该功能。
我知道,根据官方文档,Cypress 是异步工作的,我们不需要使用该wait()函数,特别是visit()命令处理该函数,因为它加载页面然后继续前进。
在我的测试用例中,我想处理导致问题的两件事:
打开左侧导航菜单上的下拉菜单。有 5 个菜单,我想要第二个
单击一个选项转到另一个页面
it("clicks on the 'Front End' and navigates to the correct page", () => {
visit(path, {
timeout: 120000,
pageLoadTimeout: 120000,
});
cy.get(selectors.CATEGORIES)
.eq(2)
// I use 'within', because I want to search **inside the
// selectors.CATEGORIES.eq(2) and not on the whole DOM**
.within(() => {
cy.get(dataCySelector("gridRow")).then(($optionsWrapper) => {
const parentEl = $optionsWrapper.parent();
const isMenuOpen = parentEl.css("display");
// if i dont add the wait(), it selects the …Run Code Online (Sandbox Code Playgroud) 我正在学习 cypress 并自动化网络应用程序。Web 应用程序有网格/表格,行是时间段,列是“桑拿”、“动感单车”、“瑜伽”等活动。行是上午 10 点、上午 11 点等。因此,如果您想预订上午 11 点的动感单车课程,您可以单击该行和列的交集。我已经浏览并尝试了有关网络表格的解决方案,我已经发布了我在最后尝试过的内容
这是 HTML:
<div class="fc-timegrid fc-resourceTimeGridDay-view fc-view"><table class="fc-scrollgrid fc-scrollgrid-liquid"><thead><tr class="fc-scrollgrid-section fc-scrollgrid-section-header "><td><div class="fc-scroller-harness"><div class="fc-scroller" style="overflow: hidden scroll;"><table class="fc-col-header " style="width: 1316px;"><colgroup><col style="width: 55px;"></colgroup><tbody><tr><th class="fc-timegrid-axis"><div class="fc-timegrid-axis-frame"></div></th><th class="fc-col-header-cell fc-resource" colspan="1" data-resource-id="QXBwb2ludG1lbnRTbG90OjMwMDE=" data-date="2023-05-11"><div class="fc-scrollgrid-sync-inner"><span class="fc-col-header-cell-cushion ">Sauna</span></div></th><th class="fc-col-header-cell fc-resource" colspan="1" data-resource-id="QXBwb2ludG1lbnRTbG90OjMwMDI=" data-date="2023-05-11"><div class="fc-scrollgrid-sync-inner"><span class="fc-col-header-cell-cushion ">Spinning</span></div>
Run Code Online (Sandbox Code Playgroud)
<tbody><tr class="fc-scrollgrid-section fc-scrollgrid-section-body fc-scrollgrid-section-liquid"><td><div class="fc-scroller-harness fc-scroller-harness-liquid"><div class="fc-scroller fc-scroller-liquid-absolute" style="overflow: hidden scroll;"><div class="fc-timegrid-body" style="width: 1316px;"><div class="fc-timegrid-slots"><table class="" style="width: 1316px;"><colgroup><col style="width: 55px;"></colgroup><tbody><tr><td class="fc-timegrid-slot fc-timegrid-slot-label fc-scrollgrid-shrink" data-time="10:00:00"><div class="fc-timegrid-slot-label-frame fc-scrollgrid-shrink-frame"><div class="fc-timegrid-slot-label-cushion fc-scrollgrid-shrink-cushion">10am</div></div></td><td class="fc-timegrid-slot fc-timegrid-slot-lane …Run Code Online (Sandbox Code Playgroud) cypress ×10
javascript ×3
chalk ×1
contains ×1
cross-domain ×1
cypress-conditional-testing ×1
cypress-task ×1
date ×1
element ×1
faker ×1
format ×1
fullcalendar ×1