Nar*_*yan 0 sorting testing automated-tests alphabetical-sort cypress
我有 2 个变量,想要检查其按字母顺序排序。
这是我的代码
cy.get('.list-item').eq(1)
.find('.activity-name span')
.invoke('text')
.then(text => {
const first = text;
cy.get('.activity').click();
cy.get('.list-item').eq(1)
.find('.activity-name span')
.invoke('text')
.then(text => {
const second = text;
// Here I want to check if the result of first element is equal second-variable
});
});
Run Code Online (Sandbox Code Playgroud)
请帮助我。我怎样才能用柏树做到这一点
根据记录,我在这里无法提供硬编码列表,因此我使用上面的内容(来自@Hung Tran)来获得更通用的解决方案:
cy.get('.list-item')
.then(items => {
const unsortedItems = items.map((index, html) => Cypress.$(html).text()).get();
const sortedItems = unsortedItems.slice().sort();
expect(unsortedItems, 'Items are sorted').to.deep.equal(sortedItems);
});
Run Code Online (Sandbox Code Playgroud)
在 Cypress 5.3.0 上运行良好
| 归档时间: |
|
| 查看次数: |
8047 次 |
| 最近记录: |