var casper = require("casper").create({
viewportSize : {
width : 1280,
height : 1024
},
clientScripts : ['includes/jquery.js'],
verbose: true,
logLevel: "debug",
});
// 送信する User-Agent ヘッダを普段使っているブラウザに合わせる
// 開発者ツールのコンソールに navigator.userAgent と打ち込むと出る
casper.userAgent("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Win64; x64; Trident/4.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)");
//システム日付
var now = new Date();
var yyyymmdd = now.getFullYear()+( "0"+( now.getMonth()+1 ) ).slice(-2)+( "0"+now.getDate() ).slice(-2);
var logdir = "slm/"+yyyymmdd+"_01"; // ログ格納場所
//ログイン画面
casper.start("https://10.XX.XX.XX:XXX/?menu=RVN");
//ログイン
casper.then(function() {
this.echo('test Login');
this.wait(2000, function() {
this.capture(logdir +'/14-test1.png');
//パスワードは定期的に変更
this.sendKeys("#login_id", "userid");
this.sendKeys("#login_pass", "password");
//ログインボタンクリック
this.click('.btn_login');
});
});
//メインメニュー
casper.then(function() {
this.echo('Main Menu');
this.wait(3000, function() {
this.capture(logdir +'/14-test2.png');
});
});
//
casper.thenOpen('https://XX.XX.XX.XX:XXXX/XXXr/XXX/Unity/?menu=RVN;domain=prd',function() {
this.echo('Release Control');
this.wait(5000, function() {
this.capture(logdir +'/14-test3.png');
});
});
//pull処理
casper.then(function() {
this.echo('Pull Out');
this.page.switchToChildFrame(0);
this.page.switchToChildFrame('left');
//処理リンククリック
this.click('a[href*="pull_complete_c1.html"]');
this.page.switchToParentFrame();
this.page.switchToParentFrame();
});
casper.then(function() {
this.capture(logdir +'/14-test4.png');
this.page.switchToChildFrame(0);
this.page.switchToChildFrame('right');
//ボタンクリック
this.evaluate(function(){
document.querySelector("input[type='submit'][value='実行']").click();
});
this.page.switchToParentFrame();
this.page.switchToParentFrame();
});
//実行登録
casper.then(function() {
this.echo('execute');
this.wait(10000, function() {
this.capture(logdir +'/14-test5.png');
this.page.switchToChildFrame(0);
this.page.switchToChildFrame('left');
//実行登録リンククリック
this.click('a[href*="Ex/ocean/show_unity_schedule_c1.html"]');
this.page.switchToParentFrame();
this.page.switchToParentFrame();
});
});
casper.then(function() {
this.capture(logdir +'/14-test6.png');
this.page.switchToChildFrame(0);
this.page.switchToChildFrame('right');
//登録ボタンクリック
this.evaluate(function(){
document.querySelector("input[type='button'][value='登録']").click();
});
casper.setFilter("page.confirm",function(message){
self.received = message;
this.echo('message to confirm:' + message);
return true;
});
this.page.switchToParentFrame();
this.page.switchToParentFrame();
});
//画面ログアウト
casper.then(function() {
this.echo('test Logout');
this.wait(1000, function() {
this.capture(logdir +'/14-test12.png');
//LOGOUTボタンクリック
this.click('a[href^="/Auth/Login/logout_e1.html"]');
});
});
casper.then(function() {
this.wait(1000, function() {
this.capture(logdir +'/14-test13.png');
});
});
処理を開始する
casper.run();