1

我似乎无法让这个断言通过。我添加了其他断言来验证字段的存在和其他一些东西来尝试让它工作,但没有运气。我觉得我可能忽略了一些明显的东西。

test_file.js

var dropdownBtn     = '.btn.dropdown-toggle';
var signinForm      = '#signin-form';
var signinDropdown  = '.dropdown-menu';

casper.start(host + '/');

casper.then(function () {
    this.test.assertUrlMatch(host, 'Guest should not be redirected');
    this.test.assertExist(signinForm, 'Signin form exists');
    this.test.assertExist(dropdownBtn, 'Signin button exists');
    this.test.assertExist('[name="nickname"]', 'Nickname field exists');
    this.test.assertExist('[name="password"]', 'Password field exists');
});

casper.thenClick(dropdownBtn, function () {
    this.test.assertVisible(signinDropdown);

    this.fill(signinForm, {
        'nickname':    'bleep',
        'password':    'bloop'
    }, false);

    this.test.assertField('nickname', 'bleep'); // undefined
    this.test.assertField('password', 'bloop'); // undefined
});

casper.run(function () {
    this.test.renderResults(true);
});

登录.html

<div class="dropdown-menu allow-click">
    <form method="post" action="#" id="signin-form">
        <div class="controls nickname">
            <label for="field-signin-nickname">Nickname</label>
            <input type="text" name="nickname" id="field-signin-nickname">
            <img class="maker-image">
        </div>
        <div class="controls password">
            <label for="field-signin-password">Password</label>
            <input type="password" name="password" id="field-signin-password">
        </div>
        <div class="controls pull-right">
            <input id="signin-btn" type="submit" class="btn btn-primary submit" value="Go!">
        </div>
    </form>
</div>

输出

Test file: test/functional/test_file.js
PASS Guest should not be redirected
PASS Signin form exists
PASS Signin button exists
PASS Nickname field exists
PASS Password field exists
PASS Selector is visible

FAIL "nickname" input field has the value "bleep"
#    type: assertField
#    subject: false
#    inputName: "nickname"
#    actual: null
#    expected: "bleep"
FAIL "password" input field has the value "bloop"
#    type: assertField
#    subject: false
#    inputName: "password"
#    actual: null
#    expected: "bloop"
FAIL 8 tests executed in 10.252s, 6 passed, 2 failed.

Details for the 2 failed tests:

In test/functional/session_signin.js:0
   assertField: "nickname" input field has the value "bleep"
In test/functional/session_signin.js:0
   assertField: "password" input field has the value "bloop"
4

0 回答 0