我正在構建一個網站,并使用 AWS Cognito 登錄作為其中的一部分。我現在想在 TestCafe 中撰寫 e2e 測驗,但我很難讓 Cognito 登錄表單與 TestCafe 一起使用。
如果未找到會話,該頁面會將您重定向到正確的 AWS Cognito OAuth“登錄”頁面。
以下測驗代碼將失敗
import { Selector } from 'testcafe';
const config = {...};
test('Logging in', async t => {
await t
.typeText(Selector('input#signInFormUsername'), config.credentials.username)
.typeText('input#signInFormPassword', config.credentials.password)
.click('input[type=submit]');
});
有錯誤
The element that matches the specified selector is not visible.
...
21 |});
22 |
23 |//then create a test and place your code there
24 |test('Logging in', async t => {
25 | await t
> 26 | .typeText(Selector('input#signInFormUsername'), config.credentials.username)
27 | .typeText('input#signInFormPassword', config.credentials.password)
28 | .click('input[type=submit]');
29 |});
30 |
事實上,當我執行測驗時
test('Logging in', async t => {
const usernameInputVisible = usernameInputSelector.visible;
await t.expect(usernameInputVisible).ok();
});
它確實失敗了。
奇怪的是a)我確實看到了元素,b)它既不是display: none也不是這里visibility: hidden描述的可見。
根據 TestCafe,該元素確實存在,因為以下內容不會失敗:
test('Logging in', async t => {
const usernameInputExists = usernameInputSelector.exists;
await t.expect(usernameInputExists).ok();
});
我在這里想念什么?如何讓 TestCafe 與 AWS Cognito OAuth 登錄頁面一起使用?
設定:
$ sw_vers
ProductName: macOS
ProductVersion: 12.2.1
BuildVersion: 21D62
$ node --version
v16.14.0
$ testcafe --version
1.18.4
我在 with 中測驗了這種行為chrome,firefox并且safari
uj5u.com熱心網友回復:
簡單的答案是每個 id 有兩個輸入,例如signInFormUsername,通過這個我們得到多個匹配每個選擇器的專案。每個選擇器的第二個元素是不可見的 ( display: none)。解決方案是過濾掉不可見的元素:
test('Logging in', async t => {
await t
.typeText(Selector('input#signInFormUsername').filterVisible(), config.credentials.username)
.typeText(Selector('input#signInFormPassword').filterVisible(), config.credentials.password)
.click(Selector('input[type=submit]').filterVisible());
});
我不是 100% 相信這是一個好的解決方案。
原始問題和解決方案可以在這里找到
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/441638.html
標籤:javascript 测试 亚马逊认知 e2e-测试 测试咖啡馆
上一篇:賽普拉斯如何使用超鏈接驗證內容?
