Reputation: 319
As the title suggests, I'm looking for a way to run Protractor tests through a batch which I would then set up a task scheduler around. I found another question on here similar to my needs but it was a dead end real quick.
Here's the ideal situation:
Scheduled Task launches a batch file that runs the webdriver server
That Batch file either A) Calls to execute another batch file for the protractor config as the problem above describes. Or B) Opens another command prompt that executes the protractor command.
Once Tests are finishes both command prompts close.
I have the super very basic 3 line batch to open the web server but am stuck on what to do next to actually kick off the tests without disrupting the webserver.
EDIT: Code Attempts
File1 contained
cd "C:\Protractor\"
call "C:\bat2.bat"
webdriver-manager start
File2 contained
START cmd /k
cd "C:\Protractor\"
protractor test.config.js
This Route opened 2 Command prompts as intended, but when the call to bat2, it would just perform the bat2 functions within the first command prompt and nothing happens in the second window. Once the jasmine specs timeout in command prompt 1, the webdriver kicks off. Which is understood based off the flow of the lines.
I've also tried combining the commands into one file but get the same results. I've tried using only one command prompt but once the webdriver starts the server, new commands can't be entered.
I guess more simply, how do I change focus between command prompts and send respective commands to each?
There's a step 4 which is out of scope but if it's easy to answer then by all means that would be amazing: After the tests execute an HTML file of reports is generated locally. I would like to automate the process of emailing those files to a particular mail group. Is that achievable through batch commands as well?
Thanks in advance for any help.
Upvotes: 0
Views: 2709
Reputation: 3645
The new versions of Protractor can start the server on their own. You need not create a separate bat file to start the server.
Please see below extract from official Protractor documentation which shows the various options of running cases.
Both 1 & 5 will work for you
exports.config = {
// ---------------------------------------------------------------------------
// ----- How to connect to Browser Drivers -----------------------------------
// ---------------------------------------------------------------------------
//
// Protractor needs to know how to connect to Drivers for the browsers
// it is testing on. This is usually done through a Selenium Server.
// There are five options - specify one of the following:
//
// 1. seleniumServerJar - to start a standalone Selenium Server locally.
// 2. seleniumAddress - to connect to a Selenium Server which is already
// running.
// 3. sauceUser/sauceKey - to use remote Selenium Servers via Sauce Labs.
// 4. browserstackUser/browserstackKey - to use remote Selenium Servers via BrowserStack.
// 5. directConnect - to connect directly to the browser Drivers.
// This option is only available for Firefox and Chrome.
Just configure Protractor conf.js with jar location & port details and it will create a local server and execute the cases
// ---- 1. To start a standalone Selenium Server locally ---------------------
// The location of the standalone Selenium Server jar file, relative
// to the location of this config. If no other method of starting Selenium
// Server is found, this will default to
// node_modules/protractor/selenium/selenium-server...
seleniumServerJar: null,
// Can be an object which will be passed to the SeleniumServer class as args.
// See a full list of options at
// https://github.com/SeleniumHQ/selenium/blob/master/javascript/node/selenium-webdriver/remote/index.js
// If you specify `args` or `port` in this object, it will overwrite the values
// set via the deprecated config values `seleniumPort` and `seleniumArgs`.
localSeleniumStandaloneOpts: {
// The port to start the Selenium Server on, or null if the server should
// find its own unused port.
port: null,
// Additional command line options to pass to selenium. For example,
// if you need to change the browser timeout, use
// seleniumArgs: ['-browserTimeout=60']
args: []
},
Just do this and you should be all good
START cmd /k
cd "C:\Protractor\"
protractor test.config.js
Upvotes: 1