-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Closed
Description
CasperJS is a browser simulator for running end-to-end browser tests. I had a simple test suite (user visits landing page, inserts email, clicks button, get success message) that was working on my app when I was using create-react-app. After migrating to Next.js, the tests break mysteriously. I think it may have to do with using Router.push, but I'm not sure. Has anyone used CasperJS on a Next.js-built app or has any idea why it might not be working? I appreciate any help.
/* sample test on CasperJS */
casper.test.begin('User can check their status', function suite(test) {
var url = casper.cli.get('url');
casper.start(url, function() {
test.assertExists('#splash-cta-1');
test.assertSelectorHasText('#splash-cta-1', 'EARLY ACCESS');
this.wait(300, function() {
this.capture('screenshots/start.png');
this.fill('form', { 'reservation[email]': 'tom@example.com' }, false);
test.assertSelectorHasText('#splash-input-1', 'tom@example.com');
this.capture('screenshots/filled-input.png');
this.click('#splash-cta-1');
test.assertSelectorHasText('#splash-cta-1', 'LOADING...');
this.capture('screenshots/loading.png');
console.log('Testing existing email...');
this.wait(3000, function() {
test.assertSelectorHasText('#waitlist-lead', "You're on the VIP list for early access! Move up the list by referring friends.");
this.capture('screenshots/correct-input.png');
});
})
});
casper.thenOpen(url, function() {
this.fill('form', { 'reservation[email]': 'tom@c' }, false);
this.click('#splash-cta-1');
console.log('Testing wrong email...');
this.wait(3000, function() {
test.assertSelectorHasText('h3', 'Mind trying again?');
});
});
casper.thenOpen(url, function() {
this.click('#splash-cta-1');
console.log('Testing empty email...');
this.wait(3000, function() {
test.assertSelectorHasText('h3', 'Mind trying again?');
});
});
casper.thenOpen(url, function() {
var newEmail = casper.cli.get('email');
if (!newEmail) {
console.log('Must provide an email address');
process.exit();
}
console.log('New email:', newEmail);
this.fill('form', { 'reservation[email]': newEmail });
this.click('#splash-cta-1');
test.assertSelectorHasText('#splash-cta-1', 'LOADING...');
console.log('Testing new email...');
this.wait(5000, function() {
test.assertSelectorHasText('.lead', "You're on the VIP list for early access! Move up the list by referring friends.");
this.capture('screenshots/correct-input.png');
});
})
});
casper.run();
Metadata
Metadata
Assignees
Labels
No labels