javascript - Filling a form in an Angular.js app using PhantomJS -
i want test angularjs application using phantomjs. first step fill login form username
field (let's assume there no other fields).
(in real browser) field controlled angular (it has ng-model
attribute) , whole form has ng-submit
attribute.
so in phantomjs script do
input username
page.evaluate(function () { document.getelementsbyname('username')[0].value = 'tester'; });
take screenshot , see 'tester' present in input
page.render('myfile.jpg');
click on submit button:
page.evaluate(function () { document.getelementbyid('go').click(); });
take screenshot.
what see happens button gets clicked, message displayed says value of username
empty. guess model not updated.
tried set these values using jquery - same result.
how correctly input values fields controlled angular?
phantomjs provides sendevent
function can used implement rudimentary sendkeys
, need focus on element first:
function sendkeys(page, selector, keys){ page.evaluate(function(selector){ // focus on text element before typing var element = document.queryselector(selector); element.click(); element.focus(); }, selector); page.sendevent("keypress", keys); } sendkeys(page, "*[name=username]", "tester");
you might want checkout either protractor seems tailored angular.js testing or casperjs builds on top of phantomjs nicer api.
Comments
Post a Comment