AssertionError: Find text within the document body casperJS/phantomJS AND how count the total number of Li with specific class name using casperJS

StackOverflow https://stackoverflow.com/questions/23219715

  •  07-07-2023
  •  | 
  •  

Frage

I tried this code :

        var casper = require('casper').create();
        var mouse = require("mouse").create(casper);
        phantom.casperTest = true;
        phantom.cookiesEnabled = true;

        phantom.addCookie({
            'name': 'authToken',
            'value': '88f115b38585155c1',
            'domain': 'localhost',
            'path': '/'
        });
        phantom.addCookie({
            'name': 'activationId',
            'value': '1',
            'domain': 'localhost',
            'path': '/'
        });
        phantom.addCookie({
            'name': 'userId',
            'value': '1',
            'domain': 'localhost',
            'path': '/'
        });
        casper.start('http://localhost/history.php', function() {
            casper.on('remote.message', function(message) {
                console.log(message);
            });
            casper.thenOpen('http://localhost/history.php', function() {
                this.page.render('cookie.jpeg');
                this.evaluate(function() {
                    console.log('cookie it here');
                    console.log("title--" + document.title);
                    console.log(document.cookie);
                });

            });
        });

        casper.then(function() {
            this.test.assertTextExists('Yesterday');
        });

        casper.run();

It gives me this error

                    root@debian:/var/www# casperjs histroyuitest_today.js
        document ready
        devicePixelRatio---1
        load history products
        [object Object],[object Object]
        cookie it here
        title--Zen
        authToken=88f115b38585155c1; activationId=1; userId=1
        FAIL Find text within the document body
        #    type: assertTextExists
        #    subject: false
        #    text: "Yesterday"
        AssertionError: Find text within the document body
          /root/phantomjs-1.9.2-linux-i686/casperjs/modules/tester.js:323 in assert
          /root/phantomjs-1.9.2-linux-i686/casperjs/modules/tester.js:766 in assertTextE                                                                                             xists
          /var/www/histroyuitest_today.js:40
          /root/phantomjs-1.9.2-linux-i686/casperjs/modules/casper.js:1558 in runStep
          /root/phantomjs-1.9.2-linux-i686/casperjs/modules/casper.js:399 in checkStep
        ⚠  looks like you did not use begin(), which is mandatory since 1.1
        FAIL AssertionError: Find text within the document body
        #    type: error
        #    subject: false
        #    error: "AssertionError: Find text within the document body"
        #    stack: in assert() in /root/phantomjs-1.9.2-linux-i686/casperjs/modules/tes                                                                                             ter.js:323
        in assertTextExists() in /root/phantomjs-1.9.2-linux-i686/casperjs/modules/teste                                                                                             r.js:766
        in anonymous() in histroyuitest_today.js:40
        in runStep() in /root/phantomjs-1.9.2-linux-i686/casperjs/modules/casper.js:1558
        in checkStep() in /root/phantomjs-1.9.2-linux-i686/casperjs/modules/casper.js:39                                                                                             9

Why am i getting this error? Are my cookies set or unset? And how can i count the total number of Li with specific class name in casperJS with a table?

War es hilfreich?

Lösung

Answer to your comment : Well it depends, i don't know if you master the CSS selectors :

this.click('li.history:nth-of-type(2) a');

but care, it takes the second li element from its parent, so the classname doesn't filter the search (it's used just to get back the correct parent). Using xpath (or jQuery with eq() ) is more intuitive (if i remember well it's something like that with xpath):

var x = require('casper').selectXPath;
this.click(x("li[@class='layout_right'][2] a"));
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top