It was a problem related with Protractor. The code that I'm showing works after all...
Run server before to run bash command on rake task
-
18-06-2023 - |
Вопрос
I'm doing a rake task in order to run tests using protractor. On my task I need:
- Run web server
- Run Selenium
- 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
Другие советы
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.
Не связан с StackOverflow