我仅在OSX和Linux中收到此错误,但Windows操作系统工作正常
org.openqa.selenium.SessionNotCreated异常:未创建会话:未找到匹配的功能 构建信息:版本:"3.11.0",修订版:"e59cfb3",时间:"2018-03-11T20:26:55.152Z">
硒版本:3.11.0 铬版本: 79.0.3945.130 Chrome 驱动程序版本:79.0.3945.36
下面是我的代码中的chrome选项。如果您遇到此问题,请告诉我
case GlobalProperties.CHROME:
System.setProperty("webdriver.chrome.driver",
PropertiesRepository.getString("global.browser.chrome.driver.executable"));
cap = DesiredCapabilities.chrome();
cap.setBrowserName(
PropertiesRepository.getString("global.browser.capability.browserName.ch"));
cap.setJavascriptEnabled(true);
cap.setCapability("platform",
PropertiesRepository.getString("global.browser.capability.platform"));
cap.setCapability("takesScreenshot", PropertiesRepository
.getBoolean("global.browser.capability.chrome.takesScreenshot"));
cap.setCapability("handlesAlerts", PropertiesRepository
.getBoolean("global.browser.capability.chrome.handlesAlerts"));
cap.setCapability("cssSelectorsEnabled", PropertiesRepository
.getBoolean("global.browser.capability.chrome.cssSelectorsEnabled"));
// Clearing session.
cap.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
// Opening incognito browser for clear cache.
cap.setCapability("chrome.switches", Arrays.asList("--incognito"));
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_settings.popups", 0);
prefs.put("download.prompt_for_download", false);
prefs.put("download.default_directory",
PropertiesRepository.getString("global.download.location"));
ChromeOptions options = new ChromeOptions();
options.addArguments("disable-infobars");
options.addArguments("chrome.switches","--disable-extensions"); // To "Disable developer mode extensions"
options.addArguments("--test-type");
options.addArguments("--disable-extensions"); //to disable browser extension popup
options.addArguments("--incognito");
options.addArguments("--no-sanbox");
options.addArguments("--headless");
options.setBinary("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome");
String extensions = PropertiesRepository
.getString("global.browser.capability.chrome.extensions");
if (extensions != null && !extensions.trim().equals("")) {
StringTokenizer tokens = new StringTokenizer(extensions, ",");
String extensionPath = PropertiesRepository
.getString("global.browser.capability.chrome.extensionpath");
File[] extFiles = new File[tokens.countTokens()];
int i = 0;
while (tokens.hasMoreElements()) {
extFiles[i] = new File(extensionPath + "/" + tokens.nextToken());
i++;
}
options.addExtensions(extFiles);
}
options.setExperimentalOption("prefs", prefs);
cap.setCapability(ChromeOptions.CAPABILITY, options);
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setCapability(ChromeOptions.CAPABILITY, options);
break;
例外
BROWSER : chrome
Jan 25, 2020 2:52:21 PM org.openqa.selenium.remote.DesiredCapabilities chrome
INFO: Using `new ChromeOptions()` is preferred to `DesiredCapabilities.chrome()`
INFO [pool-1-thread-1] (DriverFactory.java:58) - Desired Capabilities : Capabilities {acceptSslCerts: true, browserName: chrome, chrome.switches: [--incognito], cssSelectorsEnabled: true, ensureCleanSession: true, goog:chromeOptions: {args: [disable-infobars, chrome.switches, --disable-extensions, --test-type, --disable-extensions, --incognito, --no-sanbox, --headless], binary: /Applications/Google Chrome..., extensions: [], prefs: {download.default_directory: C:/download/ASMT, download.prompt_for_download: false, profile.default_content_settings.popups: 0}}, handlesAlerts: true, javascriptEnabled: true, platform: WINDOWS, takesScreenshot: true, version: }
INFO [pool-1-thread-1] (DriverFactory.java:63) - environment value ==> stage
INFO [pool-1-thread-3] (DriverFactory.java:58) - Desired Capabilities : Capabilities {acceptSslCerts: true, browserName: chrome, chrome.switches: [--incognito], cssSelectorsEnabled: true, ensureCleanSession: true, goog:chromeOptions: {args: [disable-infobars, chrome.switches, --disable-extensions, --test-type, --disable-extensions, --incognito, --no-sanbox, --headless], binary: /Applications/Google Chrome..., extensions: [], prefs: {download.default_directory: C:/download/ASMT, download.prompt_for_download: false, profile.default_content_settings.popups: 0}}, handlesAlerts: true, javascriptEnabled: true, platform: WINDOWS, takesScreenshot: true, version: }
INFO [pool-1-thread-3] (DriverFactory.java:63) - environment value ==> stage
Starting ChromeDriver 79.0.3945.36 (3582db32b33893869b8c1339e8f4d9ed1816f143-refs/branch-heads/3945@{#614}) on port 21174
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[1579985542.015][WARNING]: FromSockAddr failed on netmask
ERROR [pool-1-thread-2] (BaseTest.java:55) - Unable to load Driver
org.openqa.selenium.SessionNotCreatedException: session not created: No matching capabilities found
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:26:55.152Z'
System info: host: 'ASC-C02YQ2BYLVDQ.local', ip: 'fe80:0:0:0:1c07:496e:1e2d:7ea7%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.6', java.version: '1.8.0_231'
Driver info: driver.version: ChromeDriver
remote stacktrace: 0 chromedriver 0x000000011001ce29 chromedriver + 3817001
1 chromedriver 0x000000010ffb0f33 chromedriver + 3374899
2 chromedriver 0x000000010fd318bf chromedriver + 755903
3 chromedriver 0x000000010fcbc19e chromedriver + 274846
4 chromedriver 0x000000010fcbb9d2 chromedriver + 272850
5 chromedriver 0x000000010fcbce7d chromedriver + 278141
6 chromedriver 0x000000010fcb9fa3 chromedriver + 266147
7 chromedriver 0x000000010fc93c0d chromedriver + 109581
8 chromedriver 0x000000010fc94ba5 chromedriver + 113573
9 chromedriver 0x000000010ffdef6f chromedriver + 3563375
10 chromedriver 0x000000010ffebe3a chromedriver + 3616314
11 chromedriver 0x000000010ffebbf7 chromedriver + 3615735
12 chromedriver 0x000000010ffbe699 chromedriver + 3430041
13 chromedriver 0x000000010ffec692 chromedriver + 3618450
14 chromedriver 0x000000010ffd2e17 chromedriver + 3513879
15 chromedriver 0x0000000110001fe4 chromedriver + 3706852
16 chromedriver 0x0000000110022fc7 chromedriver + 3841991
17 libsystem_pthread.dylib 0x00007fff715812eb _pthread_body + 126
18 libsystem_pthread.dylib 0x00007fff71584249 _pthread_start + 66
19 libsystem_pthread.dylib 0x00007fff7158040d thread_start + 13
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.W3CHandshakeResponse.lambda$new$0(W3CHandshakeResponse.java:57)
at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$getResponseFunction$2(W3CHandshakeResponse.java:104)
at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:499)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:486)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:545)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:209)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:132)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:147)
at com.ascendlearning.automation.ui.driver.DriverFactory$1.initialValue(DriverFactory.java:97)
at com.ascendlearning.automation.ui.driver.DriverFactory$1.initialValue(DriverFactory.java:37)
at java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:180)
at java.lang.ThreadLocal.get(ThreadLocal.java:170)
at com.ascendlearning.automation.ui.driver.DriverFactory.getDriver(DriverFactory.java:111)
at com.ascendlearning.automation.ui.test.BaseTest.setup(BaseTest.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:517)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:601)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:845)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1153)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
INFO [pool-1-thread-2] (BaseTest.java:59) - Method name in Base Test in setup for loading properties:ASMT746_VerifyQuizBankAndItsElements
INFO [pool-1-thread-2] (PropertiesRepository.java:86) - List of files to load : stg_input.properties
INFO [pool-1-thread-2] (PropertiesRepository.java:33) - Loading property file : stg_input.properties
java.lang.NullPointerException
at com.ascendlearning.automation.ui.test.ExtentReport.takesScreenshot(ExtentReport.java:101)
at com.ascendlearning.automation.ui.test.ExtentReport.onConfigurationFailure(ExtentReport.java:132)
at org.testng.internal.Invoker.runConfigurationListeners(Invoker.java:1770)
at org.testng.internal.Invoker.handleConfigurationFailure(Invoker.java:303)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:237)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:601)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:845)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1153)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
此错误消息...
Jan 25, 2020 2:52:21 PM org.openqa.selenium.remote.DesiredCapabilities chrome
INFO: Using `new ChromeOptions()` is preferred to `DesiredCapabilities.chrome()`
INFO [pool-1-thread-1] (DriverFactory.java:58) - Desired Capabilities : Capabilities {acceptSslCerts: true, browserName: chrome, chrome.switches: [--incognito], cssSelectorsEnabled: true, ensureCleanSession: true, goog:chromeOptions: {args: [disable-infobars, chrome.switches, --disable-extensions, --test-type, --disable-extensions, --incognito, --no-sanbox, --headless], binary: /Applications/Google Chrome..., extensions: [], prefs: {download.default_directory: C:/download/ASMT, download.prompt_for_download: false, profile.default_content_settings.popups: 0}}, handlesAlerts: true, javascriptEnabled: true, platform: WINDOWS, takesScreenshot: true, version: }
INFO [pool-1-thread-1] (DriverFactory.java:63) - environment value ==> stage
INFO [pool-1-thread-3] (DriverFactory.java:58) - Desired Capabilities : Capabilities {acceptSslCerts: true, browserName: chrome, chrome.switches: [--incognito], cssSelectorsEnabled: true, ensureCleanSession: true, goog:chromeOptions: {args: [disable-infobars, chrome.switches, --disable-extensions, --test-type, --disable-extensions, --incognito, --no-sanbox, --headless], binary: /Applications/Google Chrome..., extensions: [], prefs: {download.default_directory: C:/download/ASMT, download.prompt_for_download: false, profile.default_content_settings.popups: 0}}, handlesAlerts: true, javascriptEnabled: true, platform: WINDOWS, takesScreenshot: true, version: }
INFO [pool-1-thread-3] (DriverFactory.java:63) - environment value ==> stage
Starting ChromeDriver 79.0.3945.36 (3582db32b33893869b8c1339e8f4d9ed1816f143-refs/branch-heads/3945@{#614}) on port 21174
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[1579985542.015][WARNING]: FromSockAddr failed on netmask
ERROR [pool-1-thread-2] (BaseTest.java:55) - Unable to load Driver
org.openqa.selenium.SessionNotCreatedException: session not created: No matching capabilities found
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:26:55.152Z'
System info: host: 'ASC-C02YQ2BYLVDQ.local', ip: 'fe80:0:0:0:1c07:496e:1e2d:7ea7%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.6', java.version: '1.8.0_231'
Driver info: driver.version: ChromeDriver
remote stacktrace: 0 chromedriver 0x000000011001ce29 chromedriver + 3817001
1 chromedriver 0x000000010ffb0f33 chromedriver + 3374899
2 chromedriver 0x000000010fd318bf chromedriver + 755903
。暗示ChromeDriver无法启动/生成新的浏览上下文,即Chrome浏览器会话。
您的主要问题是您使用的二进制文件版本之间的不兼容,如下所示:
- 您正在使用的 chromedriver = 79.0
- chromedriver=79.0的发行说明明确提到了以下内容:
支持Chrome版本79
- 您的Selenium客户端版本是3.11.0的2018-03-11T20:26:55.152Z,几乎早了2年。
所以Selenium客户端v3.11.0和chromedriver=79.0之间存在明显的不匹配
溶液
确保:
- 硒已升级到当前级别 版本 3.141.59。
- ChromeDriver已更新到当前的 ChromeDriver v79.0.3945.36 级别。 Chrome
- 已更新到当前的Chrome 版本 79.0级别。(根据 ChromeDriver v79.0 发行说明(
- 通过IDE清理项目工作中心,并仅使用所需的依赖项重新生成项目。
- 如果您的基本 Web 客户端版本太旧,请通过Revo 卸载程序将其卸载,并安装最新的 GA 和已发布版本的Web 客户端。
- 重新启动系统。
- 以非 root用户身份执行
@Test
。 - 始终在方法中调用
driver.quit()
tearDown(){}
以正常关闭和销毁WebDriver和Web 客户端实例。
我能够自己解决这个问题,所需的功能仍然指向平台和默认下载目录的 WINDOWS 操作系统属性。 因此,我修改了代码以根据解决问题的操作系统设置这些值。
期望的能力 :
Capabilities {acceptSslCerts: true, browserName: chrome, chrome.switches: [--incognito], cssSelectorsEnabled: true, ensureCleanSession: true, goog:chromeOptions: {args: [disable-infobars, chrome.switches, --disable-extensions, --test-type, --disable-extensions, --incognito, --no-sanbox, --headless], binary: /Applications/Google Chrome..., extensions: [], prefs: {**download.default_directory: C:/download/ASMT**, download.prompt_for_download: false, profile.default_content_settings.popups: 0}}, handlesAlerts: true, javascriptEnabled: true, **platform: WINDOWS**, takesScreenshot: true, version: }