下面是我的代碼。我可以使用瀏覽器控制臺從下拉串列中訪問和選擇專案
'''document.querySelector('#__next > div > main > div.Home_toolbar__JY_RL >
div.Home_deviceControls__nQw4V > select:nth-child(2)').selectedIndex = 3'''
但是從下面的代碼在 testcafe 中進行測驗 -
''test('Select each available Audio input device', async (browser) => {
await browser.wait(6000);
let audioDevices = Selector('#__next > div > main >
div.Home_toolbar__JY_RL > div.Home_deviceControls__nQw4V >
select:nth-child(2)'
).selectedIndex = 3
await browser.expect(audioDevicescount.selectedIndex).eql(3);
});'''
以下是我得到的錯誤 -
型別錯誤:無法設定函式的屬性 selectedIndex __$$clientFunction$$() { const testRun = builder._getTestRun(); const callsite...... } 只有一個 getter
我嘗試使用客戶端函式,但無法傳遞 selectedIndex 值。
uj5u.com熱心網友回復:
您不能使用 Selector 設定“selectedIndex”屬性,因為 Selector 是為元素查詢而創建的。要在客戶端修改元素狀態,請使用ClientFunctions機制。我創建了一個示例,演示如何使用 ClientFunction 設定 selectedIndex。請看下面的代碼:
<select>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
import { Selector, ClientFunction } from 'testcafe';
fixture `f`
.page `index.html`;
const select = Selector('select');
const setSelectedIndex = ClientFunction(index => {
select().selectedIndex = index;
}, { dependencies: { select } });
test(`t`, async t => {
await setSelectedIndex(2);
await t.expect(select.selectedIndex).eql(2);
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/425831.html
標籤:javascript 测试 自动化测试 e2e-测试 测试咖啡馆
下一篇:如何在柏樹中制作可鏈接的命令?
