如何使用webdriver.io单击网页上的所有锚点元素

势均力敌的对手

我正在尝试浏览到该URL- https://gallant-meitner-86c223.netlify.com/#/,检查a[href]页面上链接的数量,单击链接并验证该人是否存在

wdio.conf.js

exports.config = {
  runner: 'local',
  specs: [
    'test/e2e/**/*.js'
  ],
  maxInstances: 10,
  capabilities: [{
    maxInstances: 5,
    browserName: 'firefox'
  }],
  logLevel: 'info',
  bail: 0,
  baseUrl: 'http://localhost:8080',
  waitforTimeout: 10000,
  connectionRetryTimeout: 90000,
  connectionRetryCount: 3,
  services: ['selenium-standalone'],
  framework: 'jasmine',
  reporters: ['spec', 'junit'],
  jasmineNodeOpts: {
   defaultTimeoutInterval: 60000,
  }

我的测试

describe('Home', () => {
  it('should get count of the links and click on them and verify the person exists', async () => {
       await browser.url('/')
    const title = await browser.getTitle()
    expect(title).toBe('Force Vue Awakens')
    // This doesn't work as well
    const links = $$('#links a')
    const count = links.length
    expect(count).toBe(10)
    links.forEach((link) => {
      link.click()
      // Dont know how to verify each person after clicking the link
    })

  })
})

我是自动化测试和Web驱动程序的新手。任何帮助或小提琴将不胜感激!

奥列克西

forEach()方法不能与返回Promise的函数一起正常使用。您可以使用它来for ... of构建。另外请记住,如果webdriver-ioasync模式下使用则应始终解析返回Promise的方法。看一下重构测试:

describe('Home', () => {
  it('should get count of the links and click on them and verify the person exists', async () => {
    await browser.url('/')
    const title = await browser.getTitle()
    expect(title).toBe('Force Vue Awakens')
    const links = await $$('#links a') //here you missed await
    const count = links.length
    expect(count).toBe(10)
    const beforeUrl = await browser.getUrl()
    for (let link of links) {
      await link.click();
      const afterUrl = await browser.getUrl()
      expect(afterUrl).not.Equal(beforeUrl) // here use your assertion library
    } 

  })
})

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

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

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何使用WebDriver在网页上找出突出显示的元素?

来自分类Dev

如何使用 jQuery 在单击锚点时关闭所有 toastr 消息?

来自分类Dev

如何单击Webdriver中的所有匹配元素?

来自分类Dev

如何使用webdriver.io模拟ctrl单击或Shift单击?

来自分类Dev

如何使用 webdriver 单击此按钮?

来自分类Dev

如何使用Selenium Webdriver双击元素

来自分类Dev

如何使用webdriver查找按钮元素?

来自分类Dev

如何使用Selenium WebDriver滚动到元素

来自分类Dev

如何使用WebDriver查找按钮元素

来自分类Dev

如何使用WebDriver查找按钮元素

来自分类Dev

如何使用Selenium WebDriver计算网页上可用的图像数量?

来自分类Dev

如何使用Selenium WebDriver计算网页上可用的图像数量?

来自分类Dev

如何使用document.querySelectorAll选择除锚点以外的所有标签(两个元素内均不锚定)?

来自分类Dev

如何使用Selenium Webdriver等待元素不可单击?

来自分类Dev

如何使用Selenium Webdriver(Python)随机选择并单击元素?

来自分类Dev

如何使用Selenium Webdriver等待元素不可单击?

来自分类Dev

如何在Selenium WebDriver中单击网页中的所有链接

来自分类Dev

如何使用Selenium Webdriver获得所有列表项?

来自分类Dev

如何使用selendroid webdriver在移动网页中滑动?

来自分类Dev

使用Haskell Webdriver软件包查找网页上的所有文本输入

来自分类Dev

Selenium Webdriver点上的元素不可单击

来自分类Dev

Webdriver如何使用Xpath查找给定元素的父fieldset元素

来自分类Dev

如何使用Selenium Webdriver在悬停菜单中单击链接?

来自分类Dev

如何使用Selenium Webdriver测试SVG对象的单击?

来自分类Dev

如何单击使用<span>标记为Selenium Webdriver创建的按钮

来自分类Dev

如何使用Selenium WebDriver在CSS中单击div

来自分类Dev

如何单击使用<span>标记为Selenium Webdriver创建的按钮

来自分类Dev

如何使用 Selenium WebDriver (Java) 单击图像/链接

来自分类Dev

如何使用Robot Framework获取网页元素的所有xpath?

Related 相关文章

  1. 1

    如何使用WebDriver在网页上找出突出显示的元素?

  2. 2

    如何使用 jQuery 在单击锚点时关闭所有 toastr 消息?

  3. 3

    如何单击Webdriver中的所有匹配元素?

  4. 4

    如何使用webdriver.io模拟ctrl单击或Shift单击?

  5. 5

    如何使用 webdriver 单击此按钮?

  6. 6

    如何使用Selenium Webdriver双击元素

  7. 7

    如何使用webdriver查找按钮元素?

  8. 8

    如何使用Selenium WebDriver滚动到元素

  9. 9

    如何使用WebDriver查找按钮元素

  10. 10

    如何使用WebDriver查找按钮元素

  11. 11

    如何使用Selenium WebDriver计算网页上可用的图像数量?

  12. 12

    如何使用Selenium WebDriver计算网页上可用的图像数量?

  13. 13

    如何使用document.querySelectorAll选择除锚点以外的所有标签(两个元素内均不锚定)?

  14. 14

    如何使用Selenium Webdriver等待元素不可单击?

  15. 15

    如何使用Selenium Webdriver(Python)随机选择并单击元素?

  16. 16

    如何使用Selenium Webdriver等待元素不可单击?

  17. 17

    如何在Selenium WebDriver中单击网页中的所有链接

  18. 18

    如何使用Selenium Webdriver获得所有列表项?

  19. 19

    如何使用selendroid webdriver在移动网页中滑动?

  20. 20

    使用Haskell Webdriver软件包查找网页上的所有文本输入

  21. 21

    Selenium Webdriver点上的元素不可单击

  22. 22

    Webdriver如何使用Xpath查找给定元素的父fieldset元素

  23. 23

    如何使用Selenium Webdriver在悬停菜单中单击链接?

  24. 24

    如何使用Selenium Webdriver测试SVG对象的单击?

  25. 25

    如何单击使用<span>标记为Selenium Webdriver创建的按钮

  26. 26

    如何使用Selenium WebDriver在CSS中单击div

  27. 27

    如何单击使用<span>标记为Selenium Webdriver创建的按钮

  28. 28

    如何使用 Selenium WebDriver (Java) 单击图像/链接

  29. 29

    如何使用Robot Framework获取网页元素的所有xpath?

热门标签

归档