mardi 7 mars 2017

Selenium Setup With Node and Nightwatch

So I am currently trying to see what a very basic selenium setup with a Node.js would look like for Work so we can begin to implement E2E testing.

So i spun up a basic node.js server with express

const express = require('express');
const path = require('path')
const app = express()
const PORT = 3000

app.use(express.static('public'))

app.get('/', (req,res) => res.status(200).end() );


app.listen(PORT, 'localhost', (req,res) => console.log(`port running on ${PORT}`))

I spun up a very basic html/css/js FE for the sake of testing

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
  <link rel="stylesheet" href="./styles.css">
<body>
    <div id="testing-file">
        This is a test
        <span>
            <p id="ryan">Ryan</p>
        </span>
    </div>
    <script>
        console.log('hello')
    </script>
</body>
</html>

//styles

  #testing-file {
    color: red;
    font-size: 2em;
}

#ryan {
    color: blue;
    font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
}

Now here is the testing setup, this is my first time using Selenium and really trying to setup E2E from scratch like this. So, after reading the documentation all morning im coming here.

Nightwatch.json file

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

  "selenium" : {
    "start_process" : false,
    "server_path" : "",
    "log_path" : "",
    "port" : 9515,
    "cli_args" : {
      "webdriver.chrome.driver" : "./chromedriver/",
      "webdriver.gecko.driver" : "",
      "webdriver.edge.driver" : ""
    }
  },

  "test_settings" : {
    "default" : {
      "launch_url" : "http://localhost:3000",
      "selenium_port"  : 9515,
      "selenium_host"  : "localhost",
      "silent": true,
      "screenshots" : {
        "enabled" : false,
        "path" : ""
      },
      "desiredCapabilities": {
        "browserName": "firefox",
        "marionette": true
      }
    },

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

    "edge" : {
      "desiredCapabilities": {
        "browserName": "MicrosoftEdge"
      }
    }
  }
}

nightwatch.js file

module.exports = {
    src_folders: ['test/e2e/']
}

test.js file

module.exports = {
    'step one' : browser => {
        browser
          .url('http://localhost:3000')
          .waitForElementVisible('body', 200);
    }
}

Now im getting the basics going but when I run the test I recieve the error:

[E2e\test] Test Suite
=========================

Running:  step one
Error processing the server response:
 unknown command: wd/hub/session

Error retrieving a new session from the selenium server

Connection refused! Is selenium server started?
{ value: -1, error: 'Unexpected token u in JSON at position 0' }

So my belief is of course I have not setup the selenium web driver correctly and that's most likely what my issue is as it's been pretty difficult. Things to note, I am on windows. I did set my PATH variable to the path that I have the selenium driver in inside of my project folder. It seems to try to run the test but the issue looks like it's going to be related to the selenium driver not spinnning up.

My Node server is on 3000, just serving up static files and selenium if I double click on the windows web driver application says the driver is on port 9515. Now everything i've read thus far online says the port on 4444, but i don't really understand what im reading right now. So basically i need to run a simple test on the browser, chrome. Let me know if any other information is needed

Aucun commentaire:

Enregistrer un commentaire