4

I can't find any valid nightwatch configuration for safari that does not include the entire Selenium jar. The nightwatch documentation says:

Using Selenium Standalone Server used to be the de-factor standard for managing the various browser drivers and services, but starting with Nightwatch 1.0 is no longer required, nor is it recommended, unless you are testing against legacy browsers, such as Internet Explorer.

Does safari count as a legacy browser? Does anyone have an example of a working nightwatch 1.x config file that can run tests against safari?

MacOS: High Sierra 10.13.6

Safari: 12.0.2

Nightwatch: v1.0.18

My current nightwatch.json which works for Chrome but not safari:

{
  "src_folders": [
    "__tests__/e2e/tests"
  ],
  "output_folder": "__tests__/e2e/reports",
  "custom_commands_path": "",
  "custom_assertions_path": "",
  "page_objects_path": "",
  "globals_path": "",
  "webdriver": {
    "start_process": true
  },
  "test_settings": {
    "default": {
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "acceptSslCerts": true,
        "chromeOptions": {
          "args": [
            "--window-size=1440,900"
          ]
        }
      }
    },
    "devChrome": {
      "launch_url": "https://DEV_HOST",
      "globals": {
        "env": "dev"
      },
      "webdriver": {
        "server_path": "node_modules/chromedriver/lib/chromedriver/chromedriver.exe",
        "port": 9515
      }
    },
    "devSafari": {
      "launch_url": "https://DEV_HOST",
      "globals": {
        "env": "dev"
      },
      "webdriver": {
        "server_path": "/usr/bin/safaridriver",
        "port": 9515
      }
    }
  }
}

Current error I am getting when I run the devSafari config: Could not start server: must specify at least one configuration argument.

Alex Egli
  • 1,262
  • 2
  • 16
  • 34

2 Answers2

2

Got some help from the nightwatch team on GitHub (https://github.com/nightwatchjs/nightwatch-docs/issues/94) and I now have a working example config file for Nightwatch 1.x and Safari 10+. NOTE: By "working" I mean that the browser opens and I can see Nightwatch interacting with it. The tests don't actually pass the way they do in Chrome, but most likely this is just due to small browser differences that can be resolved in the test cases themselves.

{
  "src_folders": [
     "__tests__/e2e/tests"
   ],
   "output_folder": "__tests__/e2e/reports",
   "custom_commands_path": "",
   "custom_assertions_path": "",
   "page_objects_path": "",
   "globals_path": "",

   "webdriver": {
     "start_process": true,
     "server_path": "/usr/bin/safaridriver",
     "port": 4445
   },

   "test_settings": {
     "default": {
       "desiredCapabilities": {
         "browserName": "safari",
         "javascriptEnabled": true,
         "acceptSslCerts": true
       }
     },
     "safari": {
       "launch_url": "localhost",
       "desiredCapabilities": {
         "browserName":"safari"
       },
       "globals": {
         "env": "dev"
       }
     }
   }
}
  1. Run: /usr/bin/safaridriver --enable
  2. Open Safari and check Develop > Allow Remote Automation, then close safari.
  3. Run nightwatch
Alex Egli
  • 1,262
  • 2
  • 16
  • 34
0

With Safari 10+, you just need to use safari as the browserName. Then make sure to specify the correct environment when running tests. For my config, that means passing the options --env safari. Here's my nightwatch.conf.js:

module.exports = {
  src_folders: ['tests/e2e/specs'],
  output_folder: 'tests/e2e/reports',
  selenium: {
    start_process: true,
    server_path: require('selenium-server').path,
    host: '127.0.0.1',
    port: 4444,
    cli_args: {
      'WebDriver.chrome.driver': require('chromedriver').path,
    },
  },
  test_settings: {
    chrome: {
      desiredCapabilities: {
        browserName: 'chrome',
      },
    },
    safari: {
      desiredCapabilities: {
        browserName: 'safari',
        javascriptEnabled: true,
        acceptSslCerts: true,
      },
    },
  },
}
samlandfried
  • 618
  • 6
  • 11