簡體   English   中英

Vue.js e2e w Nightwatch.js如何獲取有關WebElements(WebDriver協議)的詳細信息?

[英]Vue.js e2e w Nightwatch.js how to get details on WebElements (WebDriver protocol)?

在使用Nightwatch.js進行2e2測試期間,我可以使用WebDriver協議獲取元素,但結果(res.value)是元素ID的數組...

如何獲得這些元素的詳細信息?

[ { ELEMENT: '0.03261545200301663-4' },
  { ELEMENT: '0.03261545200301663-5' } ] ' length: ' 2
FIRST ELEMENT ID:  0.03261545200301663-4
FIRST ELEMENT TAG NAME:  undefined

E2E / test.js

    module.exports = {

      'Add shoppinglist': (browser) => {
        const devServer = browser.globals.devServerURL
        // open the browser and wait for #app to be on the page
        browser.url(devServer).waitForElementVisible('#app', 5000)
        // check the title of the current active tab
        browser.expect.element('ul.nav-tabs li.active a').text.to.equal('Groceries')
        // click on add shopping list plus button
        browser.click('#addShoppingListIcon')

        // get shopping list tab title elements
        browser.elements('css selector', 'ul.nav-tabs li', (res) => {
          console.log(res.value, ' length: ', res.value.length)
          console.log('FIRST ELEMENT ID: ', res.value[0].ELEMENT)
          console.log('FIRST ELEMENT TAG NAME: ', res.value[0].tag_name)
          console.log('FIRST ELEMENT CSS CLASS: ', res.value[0].style('class'))
        })

        browser.pause(1000)
        // check the title of the active tab
        browser.expect.element('ul.nav-tabs li.active a').text.to.equal('New Shopping List')
        // check the title of the active content panel
        browser.expect.element('#app .tab-content .tab-pane.active h2').text.to.equal('New Shopping List')
        // check the default value of the footer change title input field
        browser.getValue('#app .tab-content .tab-pane.active .footer input.input[name=title]', (result) => {
          browser.assert.equal(result.value, 'New Shopping List')
        })
        browser.end()
      }
    }

應該使用ELEMENT作為后續請求的ID ...

    browser.elements('css selector', 'ul.nav-tabs li', (res) => {
      console.log(res.value, ' length: ', res.value.length)
      console.log('FIRST ELEMENT ID: ', res.value[0].ELEMENT)
      browser.elementIdAttribute(res.value[0].ELEMENT, 'class', (value) => {
        console.log('FIRST ELEMENT CLASS ATTRIBUTE: ', value)
      })
    })

    console.log
    FIRST ELEMENT CLASS ATTRIBUTE:  { sessionId: '13a05b81a71d8860df5432fc7e585ab5',
      status: 0,
      value: 'active' }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM