我正在使用Materil ui和React with Typescript,我想用Cypress编写一个自动完成测试。
- 识别自动完成组件并将其打开,
- 选择一个选项,
- 验证输入中的值
查询代码:
<div class="MuiAutocomplete-root MuiAutocomplete-hasPopupIcon css-4ec9ly-MuiAutocomplete-root" role="combobox" aria-expanded="false" xpath="1">
<div class="MuiFormControl-root MuiFormControl-fullWidth MuiTextField-root css-wb57ya-MuiFormControl-root-MuiTextField-root">
<label class="MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-sizeSmall MuiInputLabel-standard MuiFormLabel-root MuiFormLabel-colorPrimary css-577pmh-MuiFormLabel-root-MuiInputLabel-root" data-shrink="false" for="movies-filter" id="movies-filter-label" style="">Movies
</label>
<div class="MuiInput-root MuiInputBase-root MuiInputBase-colorPrimary MuiInputBase-fullWidth MuiInputBase-formControl MuiInputBase-sizeSmall MuiAutocomplete-inputRoot css-4op3e8-MuiInputBase-root-MuiInput-root">
<input aria-invalid="false" autocomplete="off" id="movies-filter" placeholder="Start typing" type="text" class="MuiInput-input MuiInputBase-input MuiInputBase-inputSizeSmall MuiAutocomplete-input MuiAutocomplete-inputFocused css-nz481w-MuiInputBase-input-MuiInput-input" aria-autocomplete="list" autocapitalize="none" spellcheck="false" value="" style="">
</div>
</div>
</div>
电影.代码.ts
- 第一次尝试:
cy.contains('.MuiAutocomplete-root', 'Movies').click(); // identify Autocomplete component & open it
cy.contains('A1-Test1').click(); // choose an option
cy.contains('.MuiAutocomplete-root', 'Movies')
.find('input')
.should('have.value', 'Movie1'); // verify the value in the input
- 第二次尝试:
cy.get('#Movies-filter').click().focused().type('Mo');
cy.contains('Movie1').click();
1条答案
按热度按时间3xiyfsfu1#
它对我的作用如下: