0
我試圖創建一個測試,它在一個選項卡中啓動,然後打開另一個選項卡,複製該頁面的內容,然後返回到第一個選項卡並將剪貼板的內容粘貼到文本域。新選項卡中的量角器錯誤
我遇到的問題是,當切換到新的標籤,它與下面的錯誤而失敗:
Failed: Error while waiting for Protractor to sync with the page: "window.angular is undefined.
這裏是我的測試代碼:
fit('Text Card - Copied from another webpage',() => {
const EC = protractor.ExpectedConditions
listView.newButton.click()
stories.createStory(storyConfigNewTextCard)
const textCard: ITextCardParts = {
title: 'Copy and Paste',
copyPaste: true,
}
// Open a second tab to yahoo.com
browser.driver.executeScript(function() {
(function(a: HTMLAnchorElement) {
document.body.appendChild(a);
a.setAttribute('href', 'https://en.wikipedia.org/wiki/Artemis')
a.dispatchEvent((function(e: MouseEvent) {
e.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, true, false, false, false, 0, null)
return e
}(document.createEvent('MouseEvents'))))}(document.createElement('a')))
})
// Switch to the second tab and copy the page to paste into the text field
browser.getAllWindowHandles().then((handles) => {
const secondWindowHandle = handles[1]
const firstWindowHandle = handles[0]
browser.switchTo().window(secondWindowHandle).then(() => {
browser.wait(() => {
browser.ignoreSynchronization = true
return EC.visibilityOf(element(by.id('firstHeading')))
}, 3000, 'Could Not Find the Correct Page')
$('body').click()
// Select all web page
$('body').sendKeys(protractor.Key.chord(protractor.Key.CONTROL, 'a'))
// Copy the web page
$('body').sendKeys(protractor.Key.chord(protractor.Key.CONTROL, 'c'))
})
// switch back to first tab
browser.switchTo().window(firstWindowHandle).then(() => {
text.createTextCard(textCard)
})
})
})
只是想知道我該如何做到這一點。我曾嘗試從使用protractor.Key.chord()
切換到webdriver.Key.chord()
,並得到了完全相同的錯誤。
我認爲問題是您切換到的標籤不是一個Angular頁面,因此是警告。當我看着你的代碼時,我發現你已經在使用'browser.ignoreSynchronization = true',但是你在切換之後使用了它,你是否嘗試在切換之前先設置它,然後在切換時恢復它? – wswebcreation
@wswebcreation我會給你一個鏡頭,讓你知道。 – DarthOpto
@wswebcreation工作出色。謝謝。 – DarthOpto