首页 > 解决方案 > 用字符串“abc”搜索页面并在登录cypress中打印搜索结果

问题描述

在此 URL 上,我需要使用字符串“abc”搜索页面并在登录 cypress 时打印出搜索结果,有人可以建议怎么做吗? http://www.way2automation.com/angularjs-protractor/webtables/

import {BasePage} from '../page-objects/base-page';
import {HomePage} from '../page-objects/home-page';

describe('Search text and print in Log', () => {
  const basePage = new BasePage();
  const homePage = new HomePage();

  it('Launch Way2', () => {
    basePage.navigate();
  });

  it('Search the page with string “xyz” and print out the search result in log', () => {
    const log = Cypress.log(homePage.serachTest());
    const l = Cypress.log(cy.get('body'));
    const t = Cypress.log(cy.get('[ng-controller=mainCtrl]'));
  });

});

标签: javascriptautomationautomated-testscypressui-automation

解决方案


您可以使用each()并遍历所有td并搜索元素。就像是:

cy.get('[ng-repeat="column in columns"]').each(($ele, i) => {
    if ($ele.text === 'xyz') {
        cy.log('Search Successful for ' + ($ele.text))
    }
})

推荐阅读