casperjs jsファイルサンプル1

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();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值