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
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.
It was a problem related with Protractor. The code that I'm showing works after all...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.