javascript - 如何访问 CodeceptJS 帮助程序中的 WebdriverIO 元素方法?

标签 javascript webdriver e2e-testing webdriver-io codeceptjs

我正在使用 CodeceptJS 和 WebDriverIO 在我的 Angular 应用程序中编写 E2E 测试。

我的 Angular 应用程序有一些带有影子 DOM 的网络组件。我想要的是获取对影子根内元素的引用并执行某些操作,如单击、检查文本等。

但是,我不确定如何访问 WebDriverIO API,然后我可以使用它来访问影子根。据我了解,CodeceptJS 本身不提供抽象层来访问具有影子根的元素,这就是我尝试使用 WebDriverIO 的原因。 WebDriverIO 有一个函数可以用来访问影子根内的元素(https://webdriver.io/docs/api/element/shadow$.html)

这是我的设置:

codecept.conf.js

exports.config = {
  output: './report/e2e',
  helpers: {
    WebDriver : {
      smartWait: 5000,
      url: 'http://localhost:4200',
      browser: "chrome",
      restart: false,
      windowSize: "1920x1680",
      timeouts: {
        "script": 60000,
        "page load": 10000
      }
    }
    DomHelper:{
      require: './e2e/src/helpers/dom.helper.js'
    }
  },
  include: {
    I: './e2e/src/steps_file.js'
  },
  mocha: {},
  bootstrap: null,
  teardown: null,
  hooks: [],
  gherkin: {
    features: './e2e/src/features/**/*.feature',
    steps: ['./e2e/src/step_definitions/basic.steps.js']
  },
  plugins: {
    screenshotOnFail: {
      enabled: true
    },
    wdio: {
      enabled: true,
      services: ['selenium-standalone']
    }
  },
  tests: './e2e/src/**/*.test.js',
  name: 'test-app'
};

最佳答案

您可以像这样在自定义 CodeceptJS 帮助程序中访问 WebdriverIO 浏览器命令:

class MyHelper extends Helper {

  async accessWd() {
    const browser = this.helpers.WebDriver.browser;
  }
}

module.exports = MyHelper;

如果要访问 WebdriverIO 元素方法,则需要选择所需的元素。

结果/返回值将具有可用的方法。

关于javascript - 如何访问 CodeceptJS 帮助程序中的 WebdriverIO 元素方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58658248/

相关文章:

javascript - 'exhaustive-deps' 的警告不断要求提供完整的 'props' 对象,而不是允许单个 'props' 方法作为依赖项

javascript - 具有包含参数的时刻 isBetween 不起作用

testing - 如何让 WebDriver 解除 Firefox 安全警报?

ruby - 将隐式等待和显式等待结合在一起会导致意外的等待时间

testing - 单击给定 X Y 值的网页区域

testing - 有没有办法让 'select' 选项打开截图?

javascript - Socket.IO SSL 连接错误不使用express

javascript - 两个重复的 ID 字段(_id 和 id)自动填充

java - 使用 headless 浏览器进行调试

reactjs - 如何使用 Material UI v4 选择包含在 ForwardRef 中的组件?