如果一個站點有兩個語言環境,GB 和 US,并且有一個我們需要斷言的標簽文本,其中 GB 表示“我的儀表板”而美國表示“我的儀表板”,我們如何在不重復測驗的情況下驗證這些文本值?
uj5u.com熱心網友回復:
- 至于“我的儀表板”/“我的儀表板”,最簡單的方法是使用該
toLowerCase()方法(@pavelsman 評論):
await t.expect(title.innerText.toLowerCase()).eql('my dashboard');
- 如果您有一個復雜的案例,您可以使用正則運算式匹配或
.contains()方法:
await t.expect(title.innerText).match(yourRegex);
await t.expect(title.innerText).contains(sameStringPartForBothCases);
- 如果這不適合您,那么您可能希望將您的預期值安排為物件以斷言完整的標題字串:
import { userVariables } from 'testcafe';
fixture `Fixture`;
test('test', async t => {
const expectedTitle = {
'en-GB': 'My dashboard',
'en-US': 'My Dashboard'
};
await t.expect(title.innerText).eql(expectedTitle[userVariables.currentLocale]);
});
在這種情況下,您需要使用一些.testcaferc.json檔案運行 TestCafe 。
“en-GB”配置包含:
{
"browsers": "chrome --lang=en-GB",
"userVariables": {
"currentLocale": "en-GB"
}
}
“en-US”配置包含:
{
"browsers": "chrome --lang=en-US",
"userVariables": {
"currentLocale": "en-US"
}
}
參考:https : //testcafe.io/documentation/402638/reference/configuration-file#uservariables
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/339302.html
上一篇:壓力測驗和斷點測驗的區別
下一篇:賽普拉斯上傳
