Selenium Grid,Vagrant,无法从 Eclipse 运行 测试

Selenium Grid, Vagrant, unable to run tests from Eclipse

我正在尝试使用 Selenium 和 Selenium Grid 2 来自动化我们的测试。为此,我创建了一个 VirtualBox VM 并将其与 vagrant 打包到一个盒子中。使用简单的批处理脚本,最终想要在 Jenkins CI 服务器上 运行 这个,我可以启动 vagrant box,但我得到:

    c:\seleniumServer>vagrant up
    Bringing machine 'default' up with 'virtualbox' provider...
    ==> default: Importing base box 'IE_Vagrant.box'...
    ==> default: Matching MAC address for NAT networking...
    ==> default: Setting the name of the  VM:seleniumServer_default_1436811491763_573
    ==> default: Clearing any previously set network interfaces...
    ==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: bridged
    ==> default: Forwarding ports...
    default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: password
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.

If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.

If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.

    If the box appears to be booting properly, you may want to increase
    the timeout ("config.vm.boot_timeout") value.        

我可以启动 Selenium Hub 和 selenium Node 并进行注册。在告诉它无法连接后,我什至可以通过 ssh 进入 vagrant box。我在盒子上安装了 cygwin 和 OpenSSH。

当我尝试 运行 来自 Eclipse 的 testNg 测试时,我得到:

Error forwarding the new session Error forwarding the request Connect to 10.0.2.15:5566 [/10.0.2.15] failed: Connection timed out: connect.

这里是相关位。

开始节点
java -jar lib/selenium-server-standalone-2.46.0.jar -role webdriver -hub http://localhost:4444/grid/register -browser browserName="chrome",version=ANY,platform=WINDOWS,maxInstances=5 -Dwebdriver.chrome.driver="c\seleniumDrivers\chromedriver.exe"

使用

启动集线器
java -jar selenium-server-standalone-2.46.0.jar -role hub

流浪文件:

Vagrant.configure(2) do |config|
config.vm.boot_timeout = "300"
config.ssh.username = "vagrant"
config.ssh.password = "vagrant"
config.vm.network "public_network"
config.vm.box = "IE_Vagrant.box"
config.vm.provider "virtualbox" do |vb|
 # Display the VirtualBox GUI when booting the machine
vb.gui = true
 #   # Customize the amount of memory on the VM:
 #   vb.memory = "1024"
end

这是我的测试:

package com.hiiq.qa.testing.gen2;

import static org.junit.Assert.assertEquals;

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class GridTest {
   private static RemoteWebDriver driver;

@BeforeClass
public void setUp() throws MalformedURLException {
    DesiredCapabilities capability = new DesiredCapabilities();
    //capability.setBrowserName("chrome");
    capability.setBrowserName(DesiredCapabilities.chrome().getBrowserName());
    capability.setPlatform(Platform.WINDOWS);
    //capability.setVersion("");
    capability.setJavascriptEnabled(true);
    driver = new RemoteWebDriver(new URL("http://10.70.1.28:4444/wd/hub"), capability);
    driver.get("http://10.1.6.112:8383");
}

@Test
public void loginTest(){    

如果 box 设置正确,请检查本教程,尤其是 virtualbox 来宾添加:https://dennypc.wordpress.com/2014/06/09/creating-a-windows-box-with-vagrant-1-6/

vagrant up 和 vagrant ssh 应该可以正常工作。

然后为端口转发设置 Vagrantfile:

Vagrant.configure(2) do |config|
  config.vm.boot_timeout = "300"
  config.ssh.username = "vagrant"
  config.ssh.password = "vagrant"
  config.vm.network "public_network"
  config.vm.box = "IE_Vagrant.box"
  config.vm.network "forwarded_port", guest: 4444, host: 4444
  config.vm.network "forwarded_port", guest: 8383, host: 8383
  config.vm.provider "virtualbox" do |vb|
    # Display the VirtualBox GUI when booting the machine
    vb.gui = true
    #   # Customize the amount of memory on the VM:
    #   vb.memory = "1024"
  end
end

通过 localhost:4444 和 localhost:8383 在您的测试中联系您的服务。