有没有一种方法可以获取 Capybara/Selenium/Rspec 中的当前子域?

Is there a method to get the current subdomain in Capybara/Selenium/Rspec?

我正在测试 Capybara,我需要知道我当前的子域,例如,如果我在 url“http://mysubdomain.192.168.0.25.xip.io:3001/”中,我想获取子域 "mysubdomain" .所以我想知道 Capybara、Selenium 或 Rspec 是否已经有这种方法。

简答:否

更长的答案:水豚提供 current_url,其中 returns 当前 url。您可以解析它,然后将主机名拆分为 '.'s.

URI.parse(current_url).hostname.split('.')[0]