2017-07-04 120 views
0

我正在使用wd library進行包括摩卡在內的自動化測試。使用wd庫進行自動化測試

這裏是我的代碼

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));   
    }); 


    }); 
}); 

我能夠獲得通過類名的元素,但我需要的元素的父元素中也是如此。

希望有人能幫助我。提前致謝。

+0

爲了讓你可以使用類名「兩對四」 browser.elementByClassName父元素(「兩對四」) – Murthi

回答

0

您需要XPath並使用/..來獲取父項。

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