我正在使用Nightmare.JS测试React应用程序。在测试时,我无法完成"点击"在“材质”UI组件上选择“字段”。因此,我无法从“菜单项”组件中选择一个选项。
请告知此问题是否有任何变通方法。
感谢。
这是我的代码块。 #product_type_code是点击选择字段的按钮。执行单击时,“选择字段”不会打开以显示“菜单项”选项。
describe ('Create a new product', function () {
describe ('given correct data', () => {
it ('should pass', done => {
nightmare
.goto ('http://localhost:8080')
.wait (2000)
.on ('page', (type, message) => {
if (type == 'alert') done ();
})
.wait (2000)
// the user successfully logs in
.type ('#login_username', 'email@email.com')
.type ('#login_password', 'password')
.click ('#login_submit')
.wait (2000)
// the user clicks on the navigation
.wait ('#appbar > div:nth-child(1) > button')
.click ('#appbar > div:nth-child(1) > button')
.wait (2000)
// the user clicks on the product link and is redirected to the product page
.click ('#product_link')
.wait (2000)
// the user clicks the search button
.click ('#product_filters_submit')
.wait (2000)
// the user clicks the "new" button to create a new product
.click ('#product_new')
.wait (2000)
// the user creates a new product
.type ('#product_description', 'AABB')
.type('#product_code', 'AABB')
.wait(2000)
.mousedown('#product_type_code > div:nth-child(1) > button > div > svg > path')
.click('#product_type_code > div:nth-child(1) > button > div > svg > path')
.wait(2000)
.click('#product_currency_mnemonic')
.select('#product_currency_mnemonic', 'USD')
.wait(2000)
.click ('#product_currency_mnemonic > div:nth-child(1) > button')
.click ('#product_currency_mnemonic')
.type ('#product_comment', 'AABB')
.type ('input[id^="undefined-undefined-Company"]', 'AABB')
.wait (10000)
.click('#product_submit')
// here the input field is cleared and then a new amount is added in
.evaluate (function () {
document.querySelector (
'input[id^="undefined-undefined-BudgetAmount"]'
).value =
'';
})
.evaluate (() => document.querySelector ('h1').innerText)
.then (function (result) {
expect (result).to.equal ('Products');
expect (result).to.not.equal ('Navigation');
done ();
})
.catch (done);
});
});
});