1

我使用苏打硒进行集成测试。以下代码有效:

我保存元素的高度并在测试中使用它:

var soda = require('soda')
    , assert = require('assert');
var browser = soda.createClient({
    host: 'localhost'
    , port: 4444
    , url: 'http://jquery.com'
    , browser: 'firefox'
});
browser.session(function(err){
    browser.open('/', function(err, body, res){
        browser.storeEval("window.jQuery('.logo').height();", "height", function(err, body, res){
            browser.getEval('${height}',function(err,val){
                if(err !== null) throw err
                console.log(val) //------ it outputs 66 in console, so it works well
                browser.testComplete(function(){ });
            });
        });
    });
})

当我尝试获取元素的文本时,window.jQuery('h2.logo').text();它失败了:

var soda = require('soda')
    , assert = require('assert');
var browser = soda.createClient({
    host: 'localhost'
    , port: 4444
    , url: 'http://jquery.com'
    , browser: 'firefox'
});
browser.session(function(err){
    browser.open('/', function(err, body, res){
        browser.storeEval("window.jQuery('h2.logo').text();", "text", function(err, body, res){
            browser.getEval('${text}',function(err,val){
                if(err !== null) throw err
                console.log(val) // ------------------------- null
                browser.testComplete(function(){ });
            });
        });
    });
})

null它在控制台中打印。所以 h2 文本为空,但是当我在浏览器控制台上检查它时,它会打印:

window.jQuery('h2.logo').text()
"jQuery"

那么如何存储 h2 文本并在测试中进一步使用它呢?

4

1 回答 1

1

谢谢,Slanec。getText 对我有用:

var soda = require('soda')
    , assert = require('assert');
var browser = soda.createClient({
    host: 'localhost'
    , port: 4444
    , url: 'http://jquery.com'
    , browser: 'firefox'
});
browser.session(function(err){
    browser.open('/', function(err, body, res){
        browser.getText('css=h2.logo',function(err,val){
            if(err !== null) throw err
            console.log(val) //------------------- jQuery
            browser.testComplete(function(){ });
        });
    });
})
于 2013-07-21T13:38:08.057 回答