![](/img/trans.png)
[英]TestCafe: Is there any limitations to the length of the URL accessed by .navigateTo method?
[英]Testcafe Test Script on one url then one other url without refresh between tests using setNativeDialogHandler/navigateTo
所以我的特定測試腳本,我需要在 2 個不同的 url 上運行測試,一個,然后另一個。 原始/夾具 url 的第 1 部分效果很好,但在第 2 部分我有這 3 個測試。
test('Button Time (based on the cue point) From Brightcove', async t => { //Critical
const dataVideoIdValue = await Selector('video-js').getAttribute('data-video-id')
await t
.setNativeDialogHandler(() => true)
.navigateTo('https://signin.brightcove.com/?redirect=https%3A%2F%2Fstudio.brightcove.com%2Fproducts%2Fvideocloud%2Fmedia%2Fvideos%2F' + dataVideoIdValue)
.typeText('#email', '******')
.typeText('#password', '******')
.click('#signinButton')
const brightcoveButtonTimeValue = Selector('.cue-point').withAttribute('data-time').getAttribute('data-time')
const cuepoint = JSON.stringify(await brightcoveButtonTimeValue);
const cuepoint2 = cuepoint.match(/\d+/g)
const cuepoint3 = parseInt(cuepoint2)
var timestamp = cuepoint3;
var minutes = Math.floor(timestamp / 60);
var seconds = timestamp % 60;
var formatted = minutes.toString().padStart(2, '0') + ':' + seconds.toString().padStart(2, '0');
console.log('\"brightcoveButtonTimeValue\":"' + formatted + '<br><br><button class=\\"accordion\\">Full Results</button><div class=\\"panel\\"><p><g class=\\"cue-point\\" data-time=\\"' + await brightcoveButtonTimeValue + '\\"></p></div>", ')
const brightcoveButtonTime = Selector('.cue-point').withAttribute('data-time')
await t.expect(brightcoveButtonTime.exists).ok()
});
test('BC Thumbnail Image', async t => { //Major
const dataVideoIdValue = await Selector('video-js').getAttribute('data-video-id')
await t
.setNativeDialogHandler(() => true)
.navigateTo('https://studio.brightcove.com/products/videocloud/media/videos/' + dataVideoIdValue)
const brightcoveThumbnailValue = Selector('img').withAttribute('alt', 'Thumbnail').getAttribute('src')
console.log('\"brightcoveButtonTime\":" ' + await brightcoveThumbnailValue + '<br><br><img width=\\"200\\" src=\\"' + await brightcoveThumbnailValue + '\\"/><br><br><button class=\\"accordion\\">Full Results</button><div class=\\"panel\\"><p><img src=\\"' + await brightcoveThumbnailValue + '\\"/></p></div>", ')
const brightcoveThumbnail = Selector('img').withAttribute('alt', 'Thumbnail')
await t.expect(brightcoveThumbnail.exists).ok()
});
test('BC Name matches IRIS page name', async t => { //Minor
const promoVersionNameMatchCheck = (await Selector('script').withText('var promoCookie').innerText).replace(/\"/g, "").replace(/\;/g, "\;<br><br>").split('=').pop().split(';')[0].trim()
const promoVersionNameFull = (await Selector('script').withText('var promoCookie').innerText).replace(/\"/g, "").replace(/var/g, "<br>var").replace(/\;/g, "\;<br><br>")
const dataVideoIdValue = await Selector('video-js').getAttribute('data-video-id')
await t
.setNativeDialogHandler(() => true)
.navigateTo('https://studio.brightcove.com/products/videocloud/media/videos/' + dataVideoIdValue)
const brightcoveTitleNameValue = Selector('.Definition-classic-1_11_1-1VYT-').withAttribute('data-test-name', 'video-name').child('.Definition-value-1_11_1-DlVkJ').innerText
console.log('\"brightcoveTitleNameValueText\":"BC Name: ' + await brightcoveTitleNameValue + '<br>IRIS page name: ' + await promoVersionNameMatchCheck + '<br><br><button class=\\"accordion\\">Full Results</button><div class=\\"panel\\"><p><div class=\\"Definition-value-1_11_1-DlVkJ\\">' + await brightcoveTitleNameValue + '</div><br><br><script><br>' + await promoVersionNameFull + '</script></p></div>"}, ')
const brightcoveTitleName = Selector('.Definition-classic-1_11_1-1VYT-').withAttribute('data-test-name', 'video-name').child('.Definition-value-1_11_1-DlVkJ')
await t.expect(brightcoveTitleName.exists).ok()
await t.expect(await promoVersionNameMatchCheck).eql(await brightcoveTitleNameValue)
});
因此,當我希望它保持在 new/2nd/navigateTo url 上時,這 3 個測試將重新加載回主夾具 URL。
我嘗試了 Test.page 方法,但它似乎不起作用。 https://devexpress.github.io/testcafe/documentation/reference/test-api/test/page.html
知道為什么這不起作用或如何防止在 2 個 url 之間重新加載嗎? 在這三個測試中的第一個之后,我希望它是https://studio.brightcove.com/products/videocloud/media/videos/*** *。
據我了解,您想在第一次測試中登錄,然后在第二次和第三次測試中繼續使用您的帳戶。
但是,TestCafe 從fixture/test 中定義的頁面開始每個測試。 這是預期的行為,因為 TestCafe 中的每個單獨測試都獨立於其他測試。 測試不會在它們之間共享 cookie/localStorage/url。
在這種情況下,您需要查看Roles Mechanism 。 它將允許您在第一次測試中登錄一次。 之后,TestCafe可以在第二次測試中恢復頁面state。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.