Java 由于未找到参数值,RemoteWeb驱动程序未初始化

Java 由于未找到参数值,RemoteWeb驱动程序未初始化,java,selenium,selenium-webdriver,testng,selenium-grid,Java,Selenium,Selenium Webdriver,Testng,Selenium Grid,我正在尝试使用Selenium Grid运行一些基本测试,我从我的讲师那里获得了下面的代码 但是,RemoveWebDriver驱动程序始终为空,因为设备始终未找到参数值 我无法理解是什么在设置参数设备的值以及如何更正此错误 我对TestNG的了解有限。我猜TestNG负责调用openBrowser函数,该函数有一个参数设备,该参数的值始终是param value not found 因此,在if else块中,设备不等于pc1或pc2,这会导致驱动程序VARABLE的值为Null 我无法理解设

我正在尝试使用Selenium Grid运行一些基本测试,我从我的讲师那里获得了下面的代码

但是,RemoveWebDriver驱动程序始终为空,因为设备始终未找到参数值

我无法理解是什么在设置参数设备的值以及如何更正此错误

我对TestNG的了解有限。我猜TestNG负责调用openBrowser函数,该函数有一个参数设备,该参数的值始终是param value not found

因此,在if else块中,设备不等于pc1pc2,这会导致驱动程序VARABLE的值为Null

我无法理解设备的价值是如何推导出来的

    
    import java.net.MalformedURLException;
    import java.net.URL;
    import org.openqa.selenium.By;
    import org.openqa.selenium.Platform;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.interactions.Actions;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.openqa.selenium.remote.RemoteWebDriver;
    import org.testng.annotations.Parameters;
    import org.testng.annotations.Test;
    
    public class gridTest
    {
    
    public static WebDriver driver ;
    
    @Parameters("System")
    @Test(priority=0)
    public void openBrowser(String device) throws MalformedURLException // device is always param-value-not-found
    {
    System.out.println("device is : " + device); 
    
    if (device.equalsIgnoreCase("pc1"))
    {
    DesiredCapabilities cap = DesiredCapabilities.chrome();
    cap.setCapability("browserVersion", "80");
    driver = new RemoteWebDriver(new URL("http://192.168.1.6:30032/wd/hub"), cap);
    }
    else if (device.equalsIgnoreCase("pc2"))
    {
    DesiredCapabilities cap = DesiredCapabilities.firefox();
    driver = new RemoteWebDriver(new URL("http://192.168.1.6:30032/wd/hub"), cap);
    
    // adding the following else block merely bypasses the issue
    } else {
    String nodeUrl = "http://192.168.1.6:30032/wd/hub" ;
    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setBrowserName("chrome");
    capabilities.setPlatform(Platform.WINDOWS);
    driver = new RemoteWebDriver(new URL(nodeUrl), capabilities);
    }
    }
    
    @Test(priority = 1)
    public void Moda()
    {
    try
    {
    //Navigate to URL
    driver.get("https://www.flipkart.com/");
    driver.manage().window().maximize();
    }
    catch (Exception e)
    {
    System.out.println(e);
    return;
    }
    
    
    // Close login modal screen
    driver.findElement(By.xpath("//*[@class='_2AkmmA _29YdH8']")).click();
    
    // Hover the menu Electronics >> MI
    WebElement men1 = driver.findElement(By.xpath("//li[@class='Wbt_B2 _1YVU3_'][1]"));
    Actions act = new Actions(driver);      
    act.moveToElement(men1).perform();
    Thread.sleep(2000);
    
    
    WebElement men2 = driver.findElement(By.xpath("//li[@class='_1KCOnI _3ZgIXy'][1]//a[contains(@href,'Electronics_0_Mi')]")); 
    men2.click();
    
    //Verify 'Latest from MI' label on the search result page
    try
    {
    Thread.sleep(3000);
    }
    catch(InterruptedException ie){
    System.out.println("Error at line 76") ;
    }
    boolean Validate = driver.findElement(By.xpath("//p[text()='Latest from MI : ']")).isDisplayed();
    System.out.println("Latest from MI element is displayed--" + Validate);
    System.out.println("Completed.") ;
    }
    }

这意味着您的测试希望在
testng.xml
文件中有
System
参数值。您必须向方法参数添加一个或添加
@Optional
注释,以便在
testng.xml
中未检测到任何值时,该参数将被设置为该可选值


查看详细信息。

系统存在于grid.xml中如何检查网格是否正常工作?我不知道什么是
grid.xml
。它不是标准的
testng
名称。您需要联系提供代码的人。我相信这是一个自定义的
testng.xml
,但是您需要覆盖自定义路径的默认路径。这可以在使用maven运行测试时完成,但我不知道如何在IDE中自定义它。