Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
84
rated 0 times [  89] [ 5]  / answers: 1 / hits: 9599  / 10 Years ago, tue, february 18, 2014, 12:00:00

I'm trying to write a test using CasperJS for a scenario where pressing Enter in an input is the trigger for the page to do something with the text otherwise typed into the input.



An abbreviated/simplified version of the CasperJS test:



casper.start('http://localhost:3000/input-demo', function() {
this.sendKeys('#demo-input', 'demo text');
this.sendKeys('#demo-input', 'uE007');
this.test.assertEquals(this.getHTML('#stage'), 'input demo');
});

casper.run();


(Where we run it as casperjs test this-test.js)



I've verified that sendKeys is getting the text into the input, but that text never shows up in the #stage element. A vanilla PhantomJS implementation of the keypress works fine, where webpage.sendEvent('keypress', 'uE007') causes the on-page event handler to fire. Looking at the source of casper.sendKeys, I see that it is delegating to the sendEvent on the Casper instance's PhantomJS instance (i.e., line 1613 in the current version of casper.js).



Any ideas? Anyone gotten these keys to work in a CasperJS test?


More From » casperjs

 Answers
0

You might want to add {keepFocus: true} to the first sendKeys call. If you see the source code, without adding a keepFocus, it is blurring the text area and that means your second sendKeys call will not accept the keypress.



This seems to work.



casper.start('http://localhost:3000/input-demo', function() {
this.sendKeys('#demo-input', 'demo text', {keepFocus: true});
this.sendKeys('#demo-input', casper.page.event.key.Enter , {keepFocus: true});
this.test.assertEquals(this.getHTML('#stage'), 'input demo');
});

casper.run();

[#47639] Monday, February 17, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kaitlynnb

Total Points: 402
Total Questions: 96
Total Answers: 109

Location: Trinidad and Tobago
Member since Fri, May 8, 2020
4 Years ago
kaitlynnb questions
;