I'm doing a rake task in order to run tests using protractor. On my task I need:

  1. Run web server
  2. Run Selenium
  3. Run my tests

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

有帮助吗?

解决方案 2

It was a problem related with Protractor. The code that I'm showing works after all...

其他提示

I think your "busy" waiting loop is not written correctly. try something like:

until server_ready?("http://localhost:3001/index") do
  sleep 1
end

instead of next until.

Another thing to consider is how to stop your services after your tests did run.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top