-2

When I am trying to execute below piece of code through command line using node nightwatch tests/login_Radius_TC2.js I keep on getting below error. I am new to nightwatch and need help in understanding the exact root cause.

I also looked at the previously asked questions but none of them were able to solve the issue. Still if there is a question which already answers this, please guide me to it.

I referred the http://nightwatchjs.org/api/#waitForElementVisible for implementation.

   module.exports = {
        'LoginRadiusGoogleLogin' : function (client) {
            client
                .url('https://lr-candidate-demo1.hub.loginradius.com/auth.aspx')
                .maximizeWindow();
                .waitForElementVisible('span[title=Sign up with Google]', 10000)
                .click('span[title=Sign up with Google]')
                .windowHandles(function(result) {
                console.log(result.value);
                var newWindow=result.value[1];
                this.switchWindow(+newWindow);
                }
                .end();
        }
    };

Below is the error message :

TEST FAILURE: 1 error during execution 0 tests failed, 0 passed. 1.834s

  Unexpected token .
               .waitForElementVisible('span[title=Sign up with Google]', 10000)
               ^

   SyntaxError: Unexpected token .
       at new Script (vm.js:84:7)
       at createScript (vm.js:264:10)
       at Object.runInThisContext (vm.js:312:10)
       at Module._compile (internal/modules/cjs/loader.js:684:28)
       at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
       at Module.load (internal/modules/cjs/loader.js:620:32)
       at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
       at Function.Module._load (internal/modules/cjs/loader.js:552:3)
       at Module.require (internal/modules/cjs/loader.js:657:17)
       at require (internal/modules/cjs/helpers.js:20:18)
Kovid Mehta
  • 531
  • 2
  • 8
  • 28
  • 1
    Remove `;` in this line `.maximizeWindow();`. – supputuri Mar 17 '19 at 19:36
  • Why would you start with a **`.`** as in `.waitForElementVisible()` once you have already completed the line with **`;`** in the previous line `maximizeWindow();`? It's a typical **SyntaxError** in your program. – undetected Selenium Mar 17 '19 at 19:38
  • Thanks @DebanjanB for the input. I have just started working on Javascript so not much familiar with the syntax and wanted to resolve the issue asap which pushed me to post it here. Will try to resolve such issues on my own moving forward. – Kovid Mehta Mar 20 '19 at 14:34

1 Answers1

0

Just remove the ; from the code

        'LoginRadiusGoogleLogin' : function (client) {
            client
                .url('https://lr-candidate-demo1.hub.loginradius.com/auth.aspx')
                .maximizeWindow()
                .waitForElementVisible('span[title=Sign up with Google]', 10000)
                .click('span[title=Sign up with Google]')
                .windowHandles(function(result) {
                console.log(result.value);
                var newWindow=result.value[1];
                this.switchWindow(+newWindow);
                }
                .end();
        }
    };```
  • Thanks @prabhakar. Looks like I was making a Syntax error but really appreciate you taking out time to post the solution. – Kovid Mehta Mar 20 '19 at 14:31