Skip to content

Instantly share code, notes, and snippets.

@ruckuus
Created March 26, 2014 17:20
Show Gist options
  • Save ruckuus/9788529 to your computer and use it in GitHub Desktop.
Save ruckuus/9788529 to your computer and use it in GitHub Desktop.
Automate JS
var cs = require("casper").create({
verbose: true,
logLevel: 'debug'
});
myUsername = cs.cli.has("username") ? cs.cli.get("username") : "";
myPassword = cs.cli.has("password") ? cs.cli.get("password") : "";
cs.start("https://twitter.com", function() {
if (this.exists('div.front-signin.js-front-signin')) {
this.echo("You are not logged in");
this.fill('form[action="https://twitter.com/sessions"]', {
"session[username_or_email]" : myUsername,
"session[password]" : myPassword
}, true);
}
});
cs.waitForSelector('#global-new-tweet-button', function() {
this.capture("logged-in.png");
if (this.exists('#global-new-tweet-button')) {
this.click('#global-new-tweet-button');
}
});
cs.waitForSelector('h3#global-tweet-dialog-header.modal-title', function() {
msg = "test string: something longer longer longer";
this.sendKeys('div#tweet-box-global.tweet-box.rich-editor.notie', msg, {
reset: true,
keepFocus: true
});
this.sendKeys('div#tweet-box-global.tweet-box.rich-editor.notie', "Hi There, Hello", {
reset: true,
keepFocus: true,
});
this.evaluate(function() {
$('div#tweet-box-global.tweet-box.rich-editor.notie > div > em').contents().remove();
});
this.capture("do_tweet.png");
this.click('button.btn.primary-btn.tweet-action.tweet-btn.js-tweet-btn');
});
cs.wait(5000, function() {
this.capture("habis_pencet.png");
});
cs.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment