I'm doing a rake task in order to run tests using protractor. On my task I need:
My problem is that I need to run web server and Selenium before to run my tests. This is my rake task:
#1: run server
Thread.new { system("bundle exec rails s -p 3001 -e test") }
next until server_ready? "http://localhost:3001/index"
#2: run Selenium. I'm trying to execute this after web server is running
Thread.new { system("webdriver-manager start") }
next until server_ready? "http://localhost:4444/wd/hub/static/resource/hub.html"
#3: run tests. I'm trying to execute this after Selenium is running
system("protractor ../web/test/protractor.conf.js")
server_ready function code. With this method I'm checking if web server and selenium are up and running
def self.server_ready? _url
begin
url = URI.parse(_url)
req = Net::HTTP.new(url.host, url.port)
res = req.request_head(url.path)
res.code == "200"
rescue Errno::ECONNREFUSED
false
end
end
My problem is not about Selenium or Protractor, my problem is how to wait one command is ready before running the next
It was a problem related with Protractor. The code that I'm showing works after all...