ebrehault / resurrectio

CasperJS test recorder Chrome extension
GNU General Public License v2.0
721 stars 106 forks source link

Login Western-Union and save Headers after Login #35

Open ziflar opened 6 years ago

ziflar commented 6 years ago

hello thanks for this code it's helpful i tried to run it and got a login to western-union and save headers on a output text file .but i have a problem to run it .

here my code

var x = require('casper').selectXPath;
casper.options.verbose = true;
casper.options.logLevel = 'debug';
casper.options.userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4';
casper.options.viewportSize = {width: 1366, height: 648};
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');
   }
});
casper.test.begin('Resurrectio test', function(test) {
   casper.start('https://www.westernunion.com/fr/fr/home.html');
   casper.waitForSelector(x("//a[normalize-space(text())='Se connecter']"),
       function success() {
           test.assertExists(x("//a[normalize-space(text())='Se connecter']"));
           this.click(x("//a[normalize-space(text())='Se connecter']"));
       },
       function fail() {
           test.assertExists(x("//a[normalize-space(text())='Se connecter']"));
   });
   casper.waitForSelector("form[name=registrnForm] input[name='txtEmailAddr']",
       function success() {
           test.assertExists("form[name=registrnForm] input[name='txtEmailAddr']");
           this.click("form[name=registrnForm] input[name='txtEmailAddr']");
       },
       function fail() {
           test.assertExists("form[name=registrnForm] input[name='txtEmailAddr']");
   });
   casper.waitForSelector("input[name='txtEmailAddr']",
       function success() {
           this.sendKeys("input[name='txtEmailAddr']", "tictoc@gmail.com");
       },
       function fail() {
           test.assertExists("input[name='txtEmailAddr']");
   });
   casper.waitForSelector("form[name=registrnForm] input[name='txtKey']",
       function success() {
           test.assertExists("form[name=registrnForm] input[name='txtKey']");
           this.click("form[name=registrnForm] input[name='txtKey']");
       },
       function fail() {
           test.assertExists("form[name=registrnForm] input[name='txtKey']");
   });
   casper.waitForSelector("input[name='txtKey']",
       function success() {
           this.sendKeys("input[name='txtKey']", "tatattctaoc");
       },
       function fail() {
           test.assertExists("input[name='txtKey']");
   });
   casper.waitForSelector("form[name=registrnForm] button#btn-do-login",
       function success() {
           test.assertExists("form[name=registrnForm] button#btn-do-login");
           this.click("form[name=registrnForm] button#btn-do-login");
       },
       function fail() {
           test.assertExists("form[name=registrnForm] button#btn-do-login");
   });
   casper.then(function() {
    casper.waitWhileSelector(x("//*[@id='notification-message']"));
  });
//========  /* GET_SCREEN */ ==========
casper.then(function(){
    console.log("Make a screenshot and save it as AfterLogin.png");
casper.waitWhileSelector(x("//*[@id='notification-message']"));
    this.capture('AfterLogin.png');
});
//========  /* HEADERS */ ==========
casper.then(function dumpHeaders(){
  console.log("getting headers");
    this.currentResponse.headers.forEach(function(header){
    console.log(header.name +': '+ header.value);
  })
})
//========  /* submit form */ ==========

   casper.run(function() {test.done();});
});

any help ?

telemehanik12 commented 2 years ago

Good afternoon. I tried this code and it didn't work for me either. I tried to run it and got the western-union login and saved the headers in the output text file. I also wanted to try it on a similar site western union locations, but I have a problem launching it. I do not understand at what stage the project is.