素胚勾勒不出你
2022-09-29 17:16:16
我想為在 URI 和 xhr 響應(yīng)中返回的鍵創(chuàng)建一個(gè)變量。我嘗試了URI的路線,因?yàn)檫@似乎是最簡單的,但不知道如何告訴它只保存URI的一部分,而不是整個(gè)值。.url().then(($url) => { const moveKey = $url.text(/someString.+?(?=\/)/); cy.log(moveKey); }) 我也嘗試過使用 和 ,但等待總是超時(shí)。cy.routecy.waitcy.server() .route('/overview').as('getMove') .wait('@getMove').then((xhr) => { const moveKey = xhr.move.key; })網(wǎng)址 = https://app.com/move/xxxxxx/overview
2 回答

開滿天機(jī)
TA貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超13個(gè)贊
多虧了@Srinu科迪的建議,我能夠使用.match
.url().then(($url) => { const moveKey = $url.match(/someString.+?(?=\/)/); cy.log(moveKey); })
日志輸出一個(gè)數(shù)組,其中包含我需要的密鑰。感謝大家的幫助!

縹緲止盈
TA貢獻(xiàn)2041條經(jīng)驗(yàn) 獲得超4個(gè)贊
這不是賽普拉斯的問題。它需要在腳本字符串上使用 lil 概念。請(qǐng)使用下面的代碼段,它按照要求工作。
it('test', ()=>{
cy.url().then(fullURL=>{
fullURL = 'https://app.com/move/xxxxxx/overview';
let arr = fullURL.substr(fullURL.indexOf('move')).split('/');
let moveKey = arr[1];
cy.log(moveKey);
}
)})
添加回答
舉報(bào)
0/150
提交
取消