0

I'm using CasperJS 1.0.2 under PhantomJS 1.8.1 on Windows 8.

Trying to write a test for a web site. The site is heavily reliant on JS and the coding principals are quite unusual, which may be creating some problems but I'm not sure.

Here is the code I'm using to test login and search function:

var url = 'http://www.testsite.com/';

var casper = require('casper').create();

casper.start();

casper.start(url, function() {
    this.echo('Page: ' + this.getTitle());
    this.capture('start.png');

    if (this.exists('input#TxtUserName')) {
        this.sendKeys('input#TxtUserName', 'testlogin');
        this.sendKeys('input#TxtPassword', 'testpass');
        this.click('input#BtnLogin');
        this.capture('loggedin.png');
    }
});

casper.then(function() {
    this.capture('beforesearch.png');
    this.sendKeys("input#txtSearch", '1002');
    this.click("input#cmdSubmit");
    this.echo('Searching');
    this.capture('aftersearch.png');
});

casper.run();

When I run this code, every page on the screen capture is the same with the exception that the login information is filled in on login.png. At no point does it actually login (using my real login credentials) after the click event. The search results also don't show after that click is fired.

Any clue what could be causing this?

Here is my waitFor code after submitting the search:

casper.waitForText("Part:", function() {
    this.capture('searchresults.png');
});
  • Nevermind about the waitFor edit. Site was just being incredibly slow during the times when I did the test. – TestyTester Feb 21 '13 at 16:15
  • Possibly related to http://stackoverflow.com/questions/14098483/casperjs-click-event-having-ajax-call/15144137#15144137 See my answer there, might help you. – Leentje Feb 28 '13 at 19:53

1 Answers1

0

You should use casper.waitFor to make sure the next page has been loaded. Otherwise phantom will take the screenshot before the form submit has been answered.

user123444555621
  • 148,182
  • 27
  • 114
  • 126
  • 1
    That works to get it to login and produce the capture, however, `waitForText('Part:')` and `waitForSelector("span:contains('Part:')")` both timeout when waiting for the search results to load. It's almost as if the `click("input#Tgnameleftmenu3_cmdSubmit")` isn't actually causing a search submit. The page normally needs 2 seconds at most to load. – TestyTester Feb 21 '13 at 15:53