Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nightwatch File Structure #40

Open
mnielsen22 opened this issue Nov 7, 2016 · 6 comments
Open

Nightwatch File Structure #40

mnielsen22 opened this issue Nov 7, 2016 · 6 comments

Comments

@mnielsen22
Copy link

I have created selenium tests before, but just page objects, test specs and parameters, I've never setup a new project from scratch. I'm having troubles figuring out what my file structure should look like.

Ideally, I'd like to be able to write multiple test suites for different web apps. So my current file structure looks like this starting off

Sandbox >> Test Suite Web App A
Test Suite Web App B

From here, what should be within each Test Suite and at what file level?
For instance, should node_modules one folder level in from the Test Suite: Sandbox >> Test Suite Web App A >> node_modules?

Should my nightwatch folder be in my node_modules folder?

The nightwatch folder contains bin, examples, index.js, lib, license.md, package.json and READEME.md, are these all in the correct order or do any of these need to be within the A Test Suite folder?

Where should the selenium.jar file go?
Where should package.json go?
Where should nightwatch.conf.js go?

I want to use the example tests that come with the package to play around with first, should I treat these as their own test suite?

Does each test suite folder need to have the same setup?

I know there are a lot of questions here, I really appreciate all the help on this.

@nelsonic
Copy link
Member

nelsonic commented Nov 8, 2016

@mnielsen22 have you followed the instructions and folder structure laid out in this repo/tutorial ?
Please let us know what is unclear with specific reference to:
https://github.com/dwyl/learn-nightwatch#step-by-step-tutorial
(thanks!)

@mnielsen22
Copy link
Author

mnielsen22 commented Nov 8, 2016

@nelsonic - Yes, I have followed the instructions. I felt that the file structure was unclear. Specifically the files and questions that I mentioned above.

@nelsonic
Copy link
Member

nelsonic commented Nov 8, 2016

@mnielsen22 the "file structure" is up to you. but what works for us is:

/lib
--/server.js
/test
--/e2e
----/your_nightwatch_test.js
.gitignore
nightwatch.conf.js
package.json

You would have node_module too and inside your selenium.jar and Chromedriver would be in node_modules/nightwatch/bin/ directory provided you followed the instructions in the readme.

package.json always goes in the root of your project. see: https://docs.npmjs.com/files/package.json

your nightwatch.conf.js should go in the root of your project (by convention so that people on your team don't have to go "looking" for it...)

node_modules/nightwatch is the NPM package downloaded when you npm install nightwatch ... don't mess about with the contents of this folder.

you can put your tests _anywhere_ you like as long as you reflect that location in your src_folder property of your nightwatch.conf.js for example: nightwatch.conf.js#L7-L9
we put our nightwatch tests in /test/e2e out of convention but that's really up to you (or your team!) you could call the folder browser-tests or automated-quality-assurance if you wanted to be specific it really does not matter. 👍

Note: next time, (ideally) if you have several questions please number them. so we can be sure we have answered them all. ✅
(or ask one question per issue...) 😉

@rchovatiya88
Copy link
Collaborator

When i started nightwatch.. i faced similar issue. To set up file structure seems very unclear even from the nightwatch website and as @nelsonic mentioned there are several ways to set up nightwatch project. Here is what i have, seems to work well.

  • Manually create folder structure
  • Download Nightwatch -> Move it inside project created
  • Download the drivers(Chrome,firefox,etc) and Standalone jar -> Move it to the proper folder
  • Properly set up json file.

Create a new folder name "TestAutomation" and underneath the folder create the following folders and input all the drivers and jar files in correct folder.

/TestAutomation
--/lib   
----/drivers 
------/chromedriver 
----/nightwatch 
----/selenium 
------/selenium-server-standalone-2.xx.jar 
--log
--pages
--reports
--screenshots
--tests
--nightwatch.js
--nightwatch.json

/TestAutomation
--/lib (manually make directory)
----/drivers (manually make directory)
------/chromedriver (download the chromedriver and move inside drivers directory)
----/nightwatch (download latest version of nightwatch from nightwatchjs.org]
----/selenium (manually make directory)
------/selenium-server-standalone-2.xx.jar (download the standalone jar and move it in selenium dir)
--log (this will help add loggin)
--pages (To set up page objects pattern)
--reports (For creating Test Result Reports)
--screenshots (Nightwatch takes screenshots automatically if enabled)
--tests (create all the tests in this folder)
--nightwatch.js (create this file in the root folder "TestAutomation" and copy paste the following code require('./lib/nightwatch/bin/runner.js'); ->This will allow the nightwatch find the runner file)
--nightwatch.json

(Here is my nightwatch.json file which will help configurations)

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

  "selenium" : {
    "start_process" : true,
    "server_path" : "lib/selenium/selenium-server-standalone-2.53.0.jar",
    "start_session" : true,
    "log_path" : "log/",
    "host" : "127.0.0.1",
    "port" : 4444,
    "cli_args" : {
      "webdriver.chrome.driver" : "lib/drivers/chromedriver"
    }
  },

  "test_settings" : {
    "chrome" : {
      "launch_url" : "http://localhost",
      "selenium_port"  : 4444,
      "selenium_host"  : "localhost",
      "silent": true,
      "screenshots" : {
        "enabled" : false,
        "path" : "screenshots/Chrome/"
      },
      "desiredCapabilities": {
        "browserName": "chrome",
        "chromeOptions": {
          "args":["disable-web-security", "ignore-certificate-errors", "--test-type"]
        }
      }
    },
    "firefox" : {
      "launch_url" : "http://localhost",
      "selenium_port"  : 4444,
      "selenium_host"  : "localhost",
      "silent": true,
      "screenshots" : {
      "enabled" : true,
      "path" : "screenshots/Firefox/"
      },
        "desiredCapabilities": {
        "browserName": "firefox",
        "javascriptEnabled": true,
        "acceptSslCerts": true
      }
    }
  }
}

@GrayedFox
Copy link

@nelsonic you deserve some serious kudos just for going into that amount of detail to answer questions of a highly subjective nature that the OP could have also pretty easily answered himself. good job

@SammyGH
Copy link

SammyGH commented Nov 10, 2017

Is there a way to send all reports from different test folders to just one report folder?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants