如何使用量角器选择组件元素?

詹姆斯·德莱尼

我有组件“添加新”,它实际上是按钮。已经尝试通过添加 css、id、className 和选择元素来选择,但我仍然不可见。

量角器中的方法应该选择“添加新”按钮。

  clickAddNewBtn() {
      console.log("Click on Add New button.");
      return element(by.css('.add-new')).click();
  }

Html:“添加新”按钮(组件):

import { Component, Output, Input } from '@angular/core';

@Component({
    selector: 'nano-add-new-button',
    template: `
    <div class='nano-f-r nano-f add-new'>
        <i class='fa fa-plus'></i>
           <span class='nano-ml-5 add-new'>
                Add New
           </span>
    </div>`
})
export class NanoAddNewButtonComponent {
}

知道为什么我不能选择组件添加新按钮的某些类 ID 或选择器吗?

Audience.e2e-spec.ts:规范测试文件:

describe('Category Rule functionality', () => {
  let loginPage: LoginPage;
  let audiencePage: AudiencePage;


  beforeEach(() => {
    loginPage = new LoginPage();
    audiencePage = new AudiencePage();
  });

  it('Auto QA bot should be able to make new Category rule and save.', () => {

    console.log("Navigate on login page");
    loginPage.navigateTo();

    console.log("Fill login form");    
    loginPage.fillCredentials();

    console.log("After login go to Audience tab"); 
    audiencePage.goToAudienceTab();

    audiencePage.clickAddNewBtn();

    audiencePage.typeTextInAudienceNameField();

    audiencePage.pickRangeLast14Days();

    audiencePage.selectCategoryRule();

    audiencePage.typeTextInCategoryRuleTextArea();

    audiencePage.clickSaveBtn();

    expect(audiencePage.getNotification()).toEqual('Audience saved');
  });
});

Audience.po.ts 文件:

 export class AudiencePage {

  navigateTo() {
    return browser.get('/private/audience');
  }

  goToAudienceTab() {
    return element(by.xpath('/html/body/nano-app/nano-private/nano-navigation/div/div[3]/a/span')).click();
  }

  clickAddNewBtn() {
    console.log("Click on Add New button.");
    return element(by.tagName('nano-add-new-button')).click();
  }

  typeTextInAudienceNameField() {
    console.log("Type text in audience name field");
    return element(by.css('.nano-white-smoke-input')).sendKeys('Test');
  }

  pickRangeLast14Days() {
    return element(by.xpath('/html/body/nano-app/nano-private/nano-modal/div/div/div/div/nano-modal-entity/nano-audience-edit/form/div/div[2]/nano-audience-date-range/div[2]/label[2]/span'));
  }

  openRuleDropdown() {
    return element(by.xpath('/html/body/nano-app/nano-private/nano-modal/div/div/div/div/nano-modal-entity/nano-audience-edit/form/div/nano-audience-rules/div[1]/div[2]/div[1]/nano-drop-down/div/button/div/span')).click();
  }

  selectCategoryRule() {
    return element(by.xpath('/html/body/nano-app/nano-private/nano-modal/div/div/div/div/nano-modal-entity/nano-audience-edit/form/div/nano-audience-rules/div[1]/div[2]/div[1]/nano-drop-down/div/ul/li[5]/button/div/span')).click();
  }

  typeTextInCategoryRuleTextArea() {
    return element(by.xpath('/html/body/nano-app/nano-private/nano-modal/div/div/div/div/nano-modal-entity/nano-audience-edit/form/div/nano-audience-rules/div[1]/div[2]/div[2]/nano-category-rule/div/textarea')).sendKeys('Test');
  }

  clickAddRuleBtn() {
    return element(by.name('button .nano-c-p')).click();
  }

  clickSaveBtn() {
    return element(by.id('save')).click();
  }

  getNotification() {
    return element(by.xpath('notification')).getText();
  }

}
詹姆斯·德莱尼

解决方案是通过所有定位器从“添加新”中选择“添加新”类。

clickAddNewBtn() {
    console.log("Click on Add New button.");
    return element.all(by.css('add new'));;
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使用量角器访问SVG元素

在使用量角器元素函数选择的元素上使用 then() 后,黄瓜量角器超时

使用量角器选择元素内的所有元素

使用量角器element.all,如何在日历元素上选择日期

mouseover元素无法使用量角器工作

通过变量使用量角器链接元素?

使用量角器在列表中选择第二个锚元素

如何使用量角器测试日期选择器?

如何使用量角器测试使用getSize()函数比较元素的宽度和高度?

如何在日食中使用量角器?

如何使用量角器获取当前网址?

如何使用量角器测试angularjs应用

如何使用量角器获取当前网址?

如何使用量角器模拟Angular服务?

如何使用量角器检查元素是否可见?

如何使用量角器将角度应用程序外部的元素定位?

如何使用量角器测试检查元素是否可单击

如何使用量角器测试元素是否具有类?

如何使用量角器按文本查找和单击表格元素?

如何使用量角器和文件conf等元素出现?

如何使用量角器查找特定的子元素

如何使用量角器打字稿单击具有_ngcontent的元素并跨度buttontext

使用量角器“期望”

使用量角器测试AngularJS应用-如何在不使用ID的情况下获取HTML元素?

如何使用量角器一步选择下拉列表中的 2 个选项

如何使用量角器从具有ng-reflect-value的选择中获取文本?

如何使用量角器在 ionic 2 混合移动应用程序中实现屏幕元素加载的等待

如何使用量角器在AngularJS中唯一地标识相似元素?

使用量角器测试时如何找到 ng-content 的最后一个元素