Sauce Labs doesn't execute javascript

I am using Selenium WebdriverJs with Mocha to run tests on Sauce Labs via Travis CI. I have isolated my problem, devoid of any project dependencies. Please, help.

So what happens if I try to define an additional object having url visit and scroll down properties inside the test script itself, and then use that object to work, then it works fine. The link to the test script is here https://github.com/Princu7/open-event-webapp/blob/stripped/test/serverTest.js

If we do it like this:

var eventPage = {                                                                                                                      

  init: function(webdriver) {                                                                                                          
    this.driver = webdriver;                                                                                                           
  },                                                                                                                                   

  visit: function(url) {                                                                                                               
    return this.driver.get(url);                                                                                                       
  },                                                                                                                                   

  scrollDown: function() {                                                                                                             
    function scroll() {                                                                                                                
      window.scrollTo(0, arguments[0]);                                                                                                
    }                                                                                                                                  
    return this.driver.executeScript(scroll, 800);                                                                                     
  }                                                                                                                                    
};     
var driver = // Initialize the selenium webdriver
eventPage.init(driver)
eventPage.visit('http://reddit.com')
eventPage.scrollDown().then(function() {
  console.log("This works fine on Sauce Labs");
});

      

This works great at Sauce Labs. Here is a link to the Travis compilation https://travis-ci.org/Princu7/open-event-webapp/builds/252652917 and a link to the sauce build https://saucelabs.com/beta/tests/4cf734a141fb42548fff1ee623130c44/logs#3

Now if I create a file called eventPage.js and import it containing all the above functions into a test script, then it doesn't work. The link to this file is https://github.com/Princu7/open-event-webapp/blob/stripped2/src/selenium/eventPage.js and the link to the test script is https://github.com/Princu7/open- event-webapp / blob / stripped2 / test / serverTest.js

module.exports = {                                                                                                                     

  init: function(webdriver) {                                                                                                          
    this.driver = webdriver;                                                                                                           
  },                                                                                                                                   

  visit: function(url) {                                                                                                               
    return this.driver.get(url);                                                                                                       
  },                                                                                                                                   

  scrollDown: function() {                                                                                                             
    function scroll() {                                                                                                                
      window.scrollTo(0, arguments[0]);                                                                                                
    }                                                                                                                                  
    return this.driver.executeScript(scroll, 800);                                                                                     
  }                                                                                                                                    
};  

      

And then import it into my test script,

var eventPage = src('path of the above file');
var driver = // Initialize the selenium driver
eventPage.init(driver) 
eventPage.visit('http://reddit.com');
eventPage.scrollDown().then(function() {
  console.log("This given an error");
});

      

This gives an error at Sauce Labs. Here is a link to the failed build on Travis CI https://travis-ci.org/Princu7/open-event-webapp/builds/252655787 and Sauce Labs link https://saucelabs.com/beta/tests/5d240513c5e74e639b9abb320316592d/logs#3 ... Just to confirm, both methods work on my local machine. Please help. I spent so much time on this. Thank you !! Have a nice day!

+3


source to share


1 answer


Modules are cached and your imported module is the class prototype. Thus, you need to create a new instance to avoid conflicts:

var EventPage = require('./EventPage.js');

var eventPage = Object.create(EventPage);
eventPage.init(driver) 
eventPage.visit('http://reddit.com');
eventPage.scrollDown().then(function() {
  console.log("This given an error");
});

      

EDIT



The problem is with istanbul. The application injects a global variable into the scroll function to track progress, but this variable remains undeclared because it is executed in the browser and not in node.

One way to overcome this problem is to call executeScript

with a script as a string:

return this.driver.executeScript("window.scrollTo(0, arguments[0]);", 800);

      

+2


source







All Articles