【问题标题】:Automation testing using wd library使用 wd 库进行自动化测试
【发布时间】:2017-07-04 10:00:40
【问题描述】:

我正在与 wd library 合作进行包括 mocha 在内的自动化测试。

这是我的代码

require('colors');
var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");
chai.use(chaiAsPromised);
chai.should();

var header = require('../pages/header.js');

var wd;
try {
  wd = require('wd');
} catch( err ) {
  wd = require('../../lib/main');
}
chaiAsPromised.transferPromiseness = wd.transferPromiseness;

describe('mocha spec examples', function() {
  this.timeout(10000);

  // returning promises and chai-as-promised is the best way
  describe("using promises and chai-as-promised", function() {
    var browser;

    before(function() {
      browser = wd.promiseChainRemote();
      return browser
        .init({browserName:'chrome'})

        .setWindowSize(1366, 1024, function(err){
       });
    });

    beforeEach(function() {
      return browser.get("http://admc.io/wd/test-pages/guinea-pig.html");
     // return browser.get("http://google.com.au");
    });

    after(function() {
    });


it("Validate the Location of Header image", function() {

         return console.log(browser.elementByClassName('i_am_a_class')
                .parentElement.getAttribute("outerHTML"));
                //.getAttribute("outerHTML")
                //.then(console.log.bind(console));           
    });


  });
});

我可以通过类名获取元素,但我还需要获取找到的元素的父元素。

【问题讨论】:

  • 要获取父元素,您可以使用类名'two-of-four' browser.elementByClassName('two-of-four')

标签: node.js selenium webdriver mocha.js


【解决方案1】:

您需要 XPath 并使用 /.. 获取父级。

it("Validate the Location of Header image", function() {
    return console.log(browser.elementByXpath('//*[@class="i_am_a_class"]/..').getAttribute("outerHTML"));

【讨论】:

    猜你喜欢
    • 2018-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-14
    • 2012-01-06
    • 1970-01-01
    相关资源
    最近更新 更多