2

I am developing simple website (html, css) and I want to write few tests against it in Protractor.

Is it possible to check that kind of website with Protractor? I have html file on my computer only. Should I run this website locally on server? I don't think I can run test on file directly.

Maciejjy
  • 147
  • 4
  • 16

2 Answers2

2

Yes, its possible to open a stand-alone local html file without hosting it on a local server.You have to add this browser.resetUrl = "file:///"in your onPrepare() function and then a browser.get("file:///C:/Users/demo/test.html") would work

There are some good examples @this question - Opening a file with protractor

Community
  • 1
  • 1
AdityaReddy
  • 3,625
  • 12
  • 25
  • Thank you. This answer really works. I still have a problem though, because I need to run this tests on few computers and path to this test will never be the same (at least until project root folder). Is it possible to set this path starting from project root folder? I tried with "../....." but that don't work. – Maciejjy Mar 19 '17 at 20:04
1

A common way to do it is to approach it in multiple steps:

  • build your application
  • run a local web server from the build directory (I think this is the part you are asking about)
  • run tests against your app served by the local web server
  • stop the local web server

Usually, this multi-step process is handled by a task runner like grunt or gulp. We use grunt, grunt-contrib-connect to serve from a directory, grunt-protractor-runner to run protractor from grunt.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195