R27 R27 - 1 month ago 22
Bash Question

Protractor conf.js gives 'no specs found' only when run through batch script's variable

I am reading a string (name of a file stored in another file) to a variable in bash script.

My original command to run is

protractor conf.js --specs 'LeadershipBoard.js'


which works good if written directly in script file. But the below does not work.

protractor conf.js --specs $value


And returns "No specs found. Finished in 0 seconds". Here is my RunConf.sh file

#!/bin/bash
value=$(<string.txt)
echo $value // 'LeadershipBoard.js'

commandForConf="protractor conf.js --specs $value"
echo $commandForConf // protractor conf.js --specs 'LeadershipBoards.js'

eval "$commandForConf" // No specs found
eval "protractor conf.js --specs 'LeadershipBoard.js'" // 6 specs found, 0 failures


I want eval "$commandForConf" to work. Here is the log on console

$ sh RunConf.sh
'LeadershipBoard.js'
protractor conf.js --specs 'LeadershipBoard.js'
[15:49:35] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
[15:49:35] I/launcher - Running 1 instances of WebDriver
Started

No specs found Finished in 0 seconds

[15:49:46] I/launcher - 0 instance(s) of WebDriver still running
[15:49:46] I/launcher - internet explorer11 #01 passed
[15:49:54] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
[15:49:54] I/launcher - Running 1 instances of WebDriver Started


6 specs, 0 failures Finished in 58.478 seconds
[15:51:00] I/launcher - 0 instance(s) of WebDriver still running
[15:51:00] I/launcher - internet explorer11 #01 passed

R27 R27
Answer

I found that the error was from the file "string.txt" to which I was saving data from a HTML save as file js function. It was having a weird character which is not shown on shell's echo or notepad text.

I tried repeating the steps in a batch file when I saw that character. I stripped the character using js regex. That solved the issue.