我正在处理selenium Cucumber Gradle项目,我看到当我用chrome浏览器执行UI Automation脚本时,它只会打开浏览器,甚至我也可以看到url显示在浏览器地址栏中,但在2秒内它会退出,并出现如下所示的异常。如有任何建议,我们将不胜感激。我正在使用最新的chrome浏览器和chrome驱动程序
输出结果===============
Given User navigates to the Rlbs website # RLbys_CardPage_Ui_Step_Test.navigates_to_the_RLby_s_website()
org.openqa.selenium.WebDriverException: unknown error: net::ERR_NAME_NOT_RESOLVED
(Session info: chrome=85.0.4183.83)
Build info: version: '4.0.0-alpha-4', revision: 'c2d955b49e'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 85.0.4183.83, chrome: {chromedriverVersion: 85.0.4183.87 (cd6713ebf92fa..., userDataDir: C:Usersxxx~1AppDataL...}, goog:chromeOption
s: {debuggerAddress: localhost:61816}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileIntera
ctability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:virtualAuthenticators: true}
Session ID: e88071b72a89d636e000150881ccb44a
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:196)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:129)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:53)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:161)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:582)
at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:282)
at com.pros.HALbrands.test.stepdefinition.HALCardPage_Ui_Step_Test.user_navigates_to_the_HALRLby_s_website(HALRLbyCardPage_Ui_Step_Test.java:40)
at ?.User navigates to the HALRLby website(file:src/test/resources/featurefile/HALRLbyCardPage_Ui.feature:5)
我可以知道抛出异常的原因是什么吗。
请在下面找到代码片段:
要素文件代码
功能:谷歌搜索功能
场景:验证谷歌搜索功能Given用户导航到谷歌网站当用户在搜索文本字段中以卡片形式输入文本时
步骤Definition
public class Test1
{
@Given("User navigates to the google website")
public void user_navigates_to_the_Google_s_website() {
driver.get("https://www.google.com/");
}
}
------------------------------调用下面的浏览器-------------------------
public WebDriver standAloneStepUp(BrowserType bType) throws Exception {
WebDriver driver;
try {
oLog.info(bType);
switch (bType) {
case CHROME:
//ChromeBrowser chrome = ChromeBrowser.class.newInstance();
//WebDriverManager.chromedriver().setup();
System. setProperty("webdriver.chrome.driver", System.getProperty("user.dir")+"\src\main\resources\driver\chromedriver.exe");
driver = new ChromeDriver();
return driver;
case FIREFOX:
// FirefoxBrowser firefox = FirefoxBrowser.class.newInstance();
// WebDriverManager.firefoxdriver().setup();
System. setProperty("webdriver.gecko.driver", System.getProperty("user.dir")+"\src\main\resources\driver\geckodriver.exe");
driver = new FirefoxDriver();
//driver = new FirefoxDriver(firefox.getFirefoxOptions());
return driver;
default:
throw new NoSutiableDriverFoundException(" Driver Not Found : " + ObjectRepo.reader.getBrowser());
}
} catch (Exception e) {
oLog.equals(e);
throw e;
}
}
我弄清楚问题出在哪里。事实上,当你访问尚未对公众开放的网站时,就会发生这种情况。所以分两步解决:
- 第一次连接到客户端VPN
- 虽然连接到了客户端VPN,但我仍然遇到了同样的问题,所以我在主机文件中添加了一些与clinet url和ip地址相关的行
主机文件的路径:C:\Windows\System32\drivers\etc\host
10.104.0.38 ida-oa.dev.dp-prv.halproducts.eastus.cloudapp.azure.com
10.104.0.38 order-inte-service-dev.dev.dp-prv.halproducts.astus.cloudapp.azure.com
<ip adress > <client env url >
在Bamboo上,构建失败,但在我的本地机器上,它运行良好。所以经过大量的研究。
要在CI/CD上运行它,我的https://example.com
没有被列入白名单。如果您有管理员访问权限,请自行操作或向DevOps 询问