【发布时间】:2021-11-27 23:05:40
【问题描述】:
我正在尝试使用 selenium 编写测试用例。我写了这段代码。我得到了这个错误
org.openqa.selenium.WebDriverException:无法解析远程响应:
但我不明白怎么回事
public static WebDriver driver=null;
ATUTestRecorder recorder;
@Parameters({"browsername"})
@BeforeTest
public void setUpBrowser(String browsername) throws ATUTestRecorderException, MalformedURLException
{
String timeStamp = new SimpleDateFormat("yy-MM-dd_HH-mm-ss").format(new Date());
recorder = new ATUTestRecorder("./ScreenRecorder/","Test_"+timeStamp+".mp4",false);
DesiredCapabilities cap =null;
if(driver==null)
{
if(browsername.equalsIgnoreCase("Firefox"))
{
// Set the path for geckodriver.exe
//System.setProperty("webdriver.gecko.driver", "./Drivers/geckodriver.exe");
//WebDriverManager.firefoxdriver().setup();
cap = DesiredCapabilities.firefox();
cap.setBrowserName("firefox");
cap.setPlatform(Platform.ANY);
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),cap);
}
// If the browser is Chrome
else if(browsername.equalsIgnoreCase("Chrome"))
{
// Set the path for chromedriver.exe
System.setProperty("webdriver.chrome.driver", "./Drivers/chromedriver.exe");
//WebDriverManager.chromedriver().setup();
cap = DesiredCapabilities.chrome();
cap.setBrowserName("chrome");
cap.setPlatform(Platform.ANY);
System.out.println(driver);
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),cap);
}
// If the browser is IE
else if(browsername.equalsIgnoreCase("IE"))
{
// Set the path for IEdriver.exe
//System.setProperty("webdriver.ie.driver", "./Drivers/IEDriverServer.exe");
//WebDriverManager.iedriver().setup();
cap = DesiredCapabilities.internetExplorer();
cap.setBrowserName("internetExplorer");
cap.setPlatform(Platform.ANY);
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),cap);
}
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get(DataConfig.baseURL);
}
recorder.start();
}
我该如何解决这个问题?
【问题讨论】:
-
请匹配 chrome 和 chromedriver 版本并检查您的 url 是否正确。并添加屏幕截图和错误跟踪
标签: selenium selenium-webdriver selenium-grid remotewebdriver