Alejandro Alvarez
Alejandro Alvarez

Reputation: 144

How to handle getting a blank page instead of the url specified in NightWatch?

I'm new in NightWatch, so I followed several tutorials, I did everything they said, but now I am getting a blank page with the header "data;", instead of the page I wanna see which is "https://www.ghandi.com.mx".

This is the json file. It seems like this problem is about the json configuration. Any help? Thanks so much!

  {
    "src_folders" : ["tests"],
    "output_folder" : "reports",

    "selenium": {
      "start_process": true,
      "start_session" :  true,
      "server_path": "C:\\Users\\Esau Alvarez\\Desktop\\selenium-server-standalone-3.13.0.jar",
      "port": 4444,
      "cli_args": {
        "webdriver.chrome.driver": "C:\\Users\\Esau Alvarez\\Desktop\\chromedriver.exe"
      }
    },

    "test_settings" : {
      "default": {
        "launch_url": "https://www.gandhi.com.mx/",
        "screenshots": {
          "enabled": false
        },
        "desiredCapabilities": {
          "browserName": "chrome",
          "marionette": true
        }
      },

      "chrome" : {
        "desiredCapabilities": {
          "browserName": "chrome",
          "webdriver": {
            "server_path": "C:\\Users\\Esau Alvarez\\Desktop\\NightWatch\\chromedriver.exe"
          }
        }
      }
    }
  }

This is my test file

module.exports = {
    "Test": function (browser) {
        browser
            .windowMaximize()
            .url("https://www.gandhi.com.mx/")
            .waitForElementVisible('body', 1000)
    }
}

Upvotes: 0

Views: 817

Answers (1)

Alapan Das
Alapan Das

Reputation: 18634

  • Under the default section, you've to configure for Firefox. Download the gecko driver and give the path under cli_args.
  • You should remove the server path from chrome desired capabilities, as it has been already mentioned above. After both changes your nightwatch.json should look something like this.
{
    "src_folders": ["tests"],
    "output_folder": "reports",

    "selenium": {
        "start_process": true,
        "start_session": true,
        "server_path": "C:\\Users\\Esau Alvarez\\Desktop\\selenium-server-standalone-3.13.0.jar",
        "port": 4444,
        "cli_args": {
            "webdriver.chrome.driver": "C:\\Users\\Esau Alvarez\\Desktop\\chromedriver.exe",
            "webdriver.gecko.driver": "Path to gecko driver.exe"
        }
    },

    "test_settings": {
        "default": {
            "launch_url": "https://www.gandhi.com.mx/",
            "screenshots": {
                "enabled": false
            },
            "desiredCapabilities": {
                "browserName": "firefox",
                "marionette": true
            }
        },

        "chrome": {
            "desiredCapabilities": {
                "browserName": "chrome"
            }
        }
    }
}

Also please increase the wait time to like 2000 or 3000 for the 'body' to be visible, just to be on the safe side.

module.exports = {
    "Test": function (browser) {
        browser
            .windowMaximize()
            .url("https://www.gandhi.com.mx/")
            .waitForElementVisible('body', 3000)
    }
}

So as per the nightwatch json, your default execution should happen in firefox. If you want to execute the same on chrome you should use the key chrome or move the chrome configurations to default section.

Upvotes: 1

Related Questions