ebrehault / resurrectio

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

String being searched for surrounded by \' instead of ' in AssertExsts/assertTitles #22

Closed thinkstylestudio closed 10 years ago

thinkstylestudio commented 10 years ago

I'm using OSX 10.8.5 and Chrome. I'm not sure if that matters. What it looks like is that the string I'm trying to search is accidently having the " or ' escaped. It's outputing \'HELLO! Canada: Daily news- Celebrity, fashion and beauty\' instead of `'HELLO! Canada: Daily news- Celebrity, fashion and beauty'``

Any ideas?

/*==============================================================================*/
/* Casper generated Mon Sep 08 2014 22:02:53 GMT-0600 (MDT) */
/*==============================================================================*/

var x = require('casper').selectXPath;
casper.options.viewportSize = {width: 1381, height: 806};
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('http://google.com');
   casper.waitForSelector("form[name=gbqf] input[name='q']",
       function success() {
           test.assertExists("form[name=gbqf] input[name='q']");
           this.click("form[name=gbqf] input[name='q']");
       },
       function fail() {
           test.assertExists("form[name=gbqf] input[name='q']");
   });
   casper.waitForSelector("input[name='q']",
       function success() {
           this.sendKeys("input[name='q']", "Hello");
       },
       function fail() {
           test.assertExists("input[name='q']");
   });
   casper.waitForSelector(x("//*[contains(text(), \'HELLO! Canada: Daily news- Celebrity, fashion and beauty\')]"),
       function success() {
           test.assertExists(x("//*[contains(text(), \'HELLO! Canada: Daily news- Celebrity, fashion and beauty\')]"));
         },
       function fail() {
           test.assertExists(x("//*[contains(text(), \'HELLO! Canada: Daily news- Celebrity, fashion and beauty\')]"));
   });

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

I was able to narrow down where the issue is.

The function:

CasperRenderer.prototype.pyrepr = function(text, escape) {
  // todo: handle non--strings & quoting
  var s =  "'" + text + "'";
  //if(escape) s = s.replace(/(['"])/g, "\\$1");
  return s;
}

the if(escape) seems to be firing true all the time. by commenting it out the strings worked properly.

thinkstylestudio commented 10 years ago

I made a hatchet job attempt to fix. What do you think? #23

ebrehault commented 10 years ago

Your fix looks good to me. I've just merged it.

Thanks !