Selenium Grid,Vagrant,无法从Eclipse

时间:2015-07-13 18:41:45

标签: selenium grid vagrant virtualbox

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

    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并注册。完成后我甚至可以进入流浪盒,告诉它它无法连接。我在盒子上设置了cygwin和OpenSSH。

当我尝试从Eclipse运行testNg测试时,我得到:

  

转发新会话时出错转发请求时出错连接到10.0.2.15:5566 [/10.0.2.15]失败:连接超时:连接。

以下是相关位。

使用

启动节点
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

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.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(){    

1 个答案:

答案 0 :(得分:0)

如果正确设置了该框,请查看本教程,尤其是添加了virtualbox guest虚拟机:https://dennypc.wordpress.com/2014/06/09/creating-a-windows-box-with-vagrant-1-6/

流浪汉和流浪汉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联系您的测试中的服务。