Last active
March 29, 2018 04:20
-
-
Save azizasm/f25675143f9bfa42fd5b76cb3fa96c60 to your computer and use it in GitHub Desktop.
Casperjs script to extract / automate maybank2u transaction view
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*==============================================================================*/ | |
/* Casperjs script to extract / automate maybank2u transaction view */ | |
/* Requiremnt : Install casperjs from http://casperjs.org/ and PhantomJS */ | |
/* Requiremnt : Update maybank2u username and password below */ | |
/* To run : casperjs test mbb.js */ | |
/*==============================================================================*/ | |
var fs = require('fs'); | |
var username = ""; | |
var password = ""; | |
var x = require('casper').selectXPath; | |
casper.options.viewportSize = { | |
width: 1366, | |
height: 662 | |
}; | |
casper.on('page.error', function(msg, trace) { | |
this.echo('Error: ' + msg, 'ERROR'); | |
for (var i = 0; i < trace.length; i++) { | |
var step = trace[i]; | |
this.echo(' ' + step.file + ' (line ' + step.line + ')', 'ERROR'); | |
} | |
}); | |
// first open Mayban2u page | |
casper.test.begin('Resurrectio test', function(test) { | |
casper.start('https://www.maybank2u.com.my/mbb/m2u/common/M2ULogin.do?action=Login'); | |
/* submit form */ | |
casper.wait(1000); | |
/* | |
casper.then(function() { | |
this.captureSelector("screenshot-1.png", "html"); | |
}); | |
*/ | |
casper.withFrame(0, function() { | |
this.capture('screenshot1.png'); | |
this.waitForSelector("form[name=loginForm] input[name='username1']", | |
function success() { | |
test.assertExists("form[name=loginForm] input[name='username1']"); | |
this.click("form[name=loginForm] input[name='username1']"); | |
}, | |
function fail() { | |
test.assertExists("form[name=loginForm] input[name='username1']"); | |
}); | |
}); | |
// Enter username | |
casper.withFrame(0, function() { | |
this.capture('screenshot2.png'); | |
this.waitForSelector("input[name='username1']", | |
function success() { | |
//fs.write('d1.html', this.getPageContent()); | |
this.sendKeys("input[name='username1']", username); | |
}, | |
function fail() { | |
test.assertExists("input[name='username1']"); | |
}); | |
}); | |
// Click Login Button | |
casper.withFrame(0, function() { | |
this.capture('screenshot3.png'); | |
this.waitForSelector("form[name=loginForm] input[type=submit][value='Login']", | |
function success() { | |
fs.write('d2.html', this.getPageContent()); | |
test.assertExists("form[name=loginForm] input[type=submit][value='Login']"); | |
this.wait(2000); | |
this.click("form[name=loginForm] input[type=submit][value='Login']"); | |
}, | |
function fail() { | |
test.assertExists("form[name=loginForm] input[type=submit][value='Login']"); | |
}); | |
}); | |
/* submit form */ | |
casper.withFrame(0, function() { | |
this.capture('screenshot4.png'); | |
this.waitForSelector("form[name=loginForm] input[type=submit][value='Yes']", | |
function success() { | |
fs.write('d4.html', this.getPageContent()); | |
test.assertExists("form[name=loginForm] input[type=submit][value='Yes']"); | |
this.click("form[name=loginForm] input[type=submit][value='Yes']"); | |
}, | |
function fail() { | |
test.assertExists("form[name=loginForm] input[type=submit][value='Yes']"); | |
}); | |
}); | |
/* submit form */ | |
// Enter Password and click login | |
casper.withFrame(0, function() { | |
this.capture('screenshot5.png'); | |
this.waitForSelector("input[name='password1']", | |
function success() { | |
this.wait(3000); | |
fs.write('d5.html', this.getPageContent()); | |
this.sendKeys("input[name='password1']", password); | |
this.click("form[name=loginForm] input[type=submit][value='Login']"); | |
}, | |
function fail() { | |
test.assertExists("input[name='password1']"); | |
}); | |
}); | |
/* | |
casper.withFrame(0, function() { | |
this.capture('screenshot6.png'); | |
fs.write('d6.html', this.getPageContent()); | |
this.waitForSelector("form[name=loginForm] input[type=submit][value='Login']", | |
function success() { | |
test.assertExists("form[name=loginForm] input[type=submit][value='Login']"); | |
this.wait(2000); | |
this.click("form[name=loginForm] input[type=submit][value='Login']"); | |
}, | |
function fail() { | |
test.assertExists("form[name=loginForm] input[type=submit][value='Login']"); | |
}); | |
}); | |
*/ | |
// click account link | |
casper.withFrame(0, function() { | |
this.capture('screenshot7.png'); | |
fs.write('d7.html', this.getPageContent()); | |
this.waitForSelector("ul:nth-child(8) li:nth-child(1) strong", | |
function success() { | |
test.assertExists("ul:nth-child(8) li:nth-child(1) strong"); | |
this.click("ul:nth-child(8) li:nth-child(1) strong"); | |
}, | |
function fail() { | |
test.assertExists("ul:nth-child(8) li:nth-child(1) strong"); | |
}); | |
}); | |
// click on account number link | |
casper.withFrame(0, function() { | |
this.capture('screenshot8.png'); | |
fs.write('d8.html', this.getPageContent()); | |
this.waitForSelector(".alt u", | |
function success() { | |
test.assertExists(".alt u"); | |
this.click(".alt u"); | |
}, | |
function fail() { | |
test.assertExists(".alt u"); | |
}); | |
}); | |
// click on Transaction history hyperlink | |
casper.withFrame(0, function() { | |
this.capture('screenshot9.png'); | |
fs.write('d9.html', this.getPageContent()); | |
this.waitForSelector(x("//a[normalize-space(text())='Transaction history']"), | |
function success() { | |
test.assertExists(x("//a[normalize-space(text())='Transaction history']")); | |
this.click(x("//a[normalize-space(text())='Transaction history']")); | |
}, | |
function fail() { | |
test.assertExists(x("//a[normalize-space(text())='Transaction history']")); | |
}); | |
}); | |
// View transaction details | |
casper.withFrame(0, function() { | |
this.wait(1000); | |
this.capture('screenshot10.png'); | |
fs.write('d10.html', this.getPageContent()); | |
}); | |
// TODO : Export transaction details to Excel file | |
/* | |
casper.on('load.started', function(resource) { | |
casper.echo(casper.getPageContent()); | |
}); | |
*/ | |
/* submit form */ | |
casper.run(function() { | |
test.done(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment