java - Selenium GRID 测试执行

标签 java selenium grid

我正在努力不在本地运行我的 Selenium 测试,而是在网格中运行。 我以为我做得很好,但我无法让它运行。 HUB 和 NODE 已启动并正在运行(以 CMD 启动),并且我正在使用正确的 IP 地址。 请让我知道我做错了什么!您认为这可能是代理的问题吗?

问候Arno(来自德国的学生)

// Import all the stuff I need


public class MpreisScreenshot_ID {

private String baseUrl;

  private boolean acceptNextAlert = true;
  private StringBuffer verificationErrors = new StringBuffer();

  @BeforeClass(alwaysRun = true)
  public void setUp() throws Exception {


    String requiredBrowser = "firefox";


    }
    //the "if" underneath is just for a selection (to make it better to read 
   // I  deleted the others)

     if (requiredBrowser == "firefox")
    {  
    DesiredCapabilities capabilityFirefox = DesiredCapabilities.firefox();
        capabilityFirefox.setBrowserName("firefox");
        capabilityFirefox.setVersion("54");
        WebDriver driver= new RemoteWebDriver(new 
URL("http://***.***.***.**:4445/grid/register"),capabilityFirefox); 
    } 




    baseUrl = "http://*****/****";
  //  driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
  }

WebDriver driver;


@Test
public void captureScreenshot() throws Exception 
{ 
//Start of Selenium test

// Maximize the browser

driver.manage().window().maximize();

// deleted all the steps




 @AfterMethod
 public void tearDown(ITestResult result)
 {

 // Test failing or Passing?
 if(ITestResult.FAILURE==result.getStatus())
 { 
try 
{
// Create reference of TakesScreenshot



TakesScreenshot ts=(TakesScreenshot)driver;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss");
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
String uhrzeit= sdf.format(timestamp);
// Call method to capture screenshot
File source=ts.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(source, new File("D:\\DATA\\Selenium\\TestNG-
 Screenshots\\"+result.getName()+uhrzeit+".png"));

System.out.println("Screenshot taken");

} 
catch (Exception e)
{

System.out.println("Exception while taking screenshot "+e.getMessage());
} 



}
// close application
driver.quit();
}
}

最佳答案

检查您的网址,通常 Selenium Hub 的默认端口是 4444,还可以尝试以下操作:

http://youripaddress:4444/wd/hub/

关于java - Selenium GRID 测试执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45239365/

相关文章:

Java:并发修改异常

java - 如何处理页面关闭时的 'Are you sure you want to navigate away from this page'?

java - Tomcat创建0字节文件

javascript - Angular 4 + Angular Material 2 + Angular 柔性布局?

java - 为什么 close() 输入流很好?

java - 使用 java hibernate 插入

python - 输入隐藏的文本框并按回车键(Selenium、Python)

css - 选择 CSS 网格/框架

使用回溯的随机遍历 N * M 网格的复杂性

java - 将字符串解析为日期