Using Selenium Grid to run Safari on MacOS Mojave - java

I'm trying to do a basic test using Selenium Grid to start Safari on a MacOS.
I have registered the node and its appears in my hub as the following.
Hub Confirmating node is up
browserTimeout: 0
debug: false
host: 10.120.45.211
port: 5558
role: node
timeout: 1800
cleanUpCycle: 5000
maxSession: 5
capabilities: Capabilities {browserName: Safari, maxInstances: 1,
platform: MAC, platformName: MAC, seleniumProtocol: WebDriver,
server:CONFIG_UUID: 1ba7b7b4-556c-430a-ab84-157...}
downPollingLimit: 2
hub: http://10.120.45.245:4444/grid/register
id: http://10.120.45.211:5558
nodePolling: 5000
nodeStatusCheckTimeout: 5000
proxy: org.openqa.grid.selenium.proxy.DefaultRemoteProxy
register: true
registerCycle: 5000
remoteHost: http://10.120.45.211:5558
unregisterIfStillDownAfter: 60000
I understand that SafariDriver is now available directly within macOS and i'm using these steps to make sure it setup correctly.
If you haven’t already done so, make the Develop menu available. Choose Safari > Preferences, and on the Advanced tab, select “Show Develop menu in menu bar.” For details, see Safari Help.
Choose Develop > Allow Remote Automation.
Authorize safaridriver to launch the XPC service that hosts the local web server. To permit this, manually run /usr/bin/safaridriver once and follow the authentication prompt.
This is my JAVA code:
package SeleniumGrid;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class SafariRemoteAccess {
public static void main(String[] args) throws MalformedURLException {
DesiredCapabilities dc = new DesiredCapabilities();
dc.setBrowserName("Safari");
//Point to hub
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), dc);
// Go to website via NODE
driver.get("https://www.hsbc.co.uk/");
driver.quit();
}
}
When I run the program i getting the following message.
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create session from {
"desiredCapabilities": {
"browserName": "Safari",
"server:CONFIG_UUID": "1ba7b7b4-556c-430a-ab84-1574fc7ea584"
},
"capabilities": {
"firstMatch": [
{
"browserName": "Safari",
"server:CONFIG_UUID": "1ba7b7b4-556c-430a-ab84-1574fc7ea584"
}
]
}
}
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'Mishal-Shahs-MacBook-Pro.local', ip: 'fe80:0:0:0:c9b:214f:9f0:2788%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.2', java.version: '1.8.0_202'
Driver info: driver.version: unknown
Command duration or timeout: 198 milliseconds**
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$errorHandler$0(JsonWireProtocolResponse.java:54)
at org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0(HandshakeResponse.java:30)
at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:126)
at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
at java.util.Spliterators$ArraySpliterator.tryAdvance(Unknown Source)
at java.util.stream.ReferencePipeline.forEachWithCancel(Unknown Source)
at java.util.stream.AbstractPipeline.copyIntoWithCancel(Unknown Source)
at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.util.stream.FindOps$FindOp.evaluateSequential(Unknown Source)
at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.util.stream.ReferencePipeline.findFirst(Unknown Source)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:128)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:74)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:144)
at SeleniumGrid.SafariRemoteAccess.main(SafariRemoteAccess.java:17)
Caused by: org.openqa.selenium.SessionNotCreatedException: Unable to create session from {
"desiredCapabilities": {
"browserName": "Safari",
"server:CONFIG_UUID": "1ba7b7b4-556c-430a-ab84-1574fc7ea584"
},
"capabilities": {
"firstMatch": [
{
"browserName": "Safari",
"server:CONFIG_UUID": "1ba7b7b4-556c-430a-ab84-1574fc7ea584"
}
]
}
}
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'Mishal-Shahs-MacBook-Pro.local', ip: 'fe80:0:0:0:c9b:214f:9f0:2788%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.2', java.version: '1.8.0_202'
Driver info: driver.version: unknown
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'LAPTOP-1MOS5JFR', ip: '10.120.45.245', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_192'
Driver info: driver.version: unknown
at org.openqa.selenium.remote.server.NewSessionPipeline.lambda$null$4(NewSessionPipeline.java:76)
at java.util.Optional.orElseThrow(Optional.java:290)
at org.openqa.selenium.remote.server.NewSessionPipeline.lambda$createNewSession$5(NewSessionPipeline.java:75)
at java.util.Optional.orElseGet(Optional.java:267)
at org.openqa.selenium.remote.server.NewSessionPipeline.createNewSession(NewSessionPipeline.java:73)
at org.openqa.selenium.remote.server.commandhandler.BeginSession.execute(BeginSession.java:65)
at org.openqa.selenium.remote.server.WebDriverServlet.lambda$handle$0(WebDriverServlet.java:235)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
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)
Update
This is the code im using to setup the NODE on the MacOS machine:
java -Dwebdriver.safari.driver=/System/Library/CoreServices/SafariSupport.bundle/Contents/MacOS/safaridriver.exe -jar selenium-server-standalone-3.141.59.jar -role node -hub 10.120.45.245:4444/grid/register -port 5558 -browser "browserName=Safari, platform=MAC, platformName=MAC, maxInstances=1"

It is not clear from your error stack trace if the Selenium Grid is on Mac OS X and to start the Selenium Node you are using the command:
java -Dwebdriver.safari.driver=/System/Library/CoreServices/SafariSupport.bundle/Contents/MacOS/safaridriver.exe -jar selenium-server-standalone-3.141.59.jar -role node -hub 10.120.45.245:4444/grid/register -port 5558 -browser "browserName=Safari, platform=MAC, platformName=MAC, maxInstances=1"
why would you see the error log as (relates to Selenium Grid):
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'Mishal-Shahs-MacBook-Pro.local', ip: 'fe80:0:0:0:c9b:214f:9f0:2788%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.2', java.version: '1.8.0_202'
Driver info: driver.version: unknown
Then again (first set relates to Mac OS X and second set relates to Windows 10):
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'Mishal-Shahs-MacBook-Pro.local', ip: 'fe80:0:0:0:c9b:214f:9f0:2788%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.2', java.version: '1.8.0_202'
Driver info: driver.version: unknown
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'LAPTOP-1MOS5JFR', ip: '10.120.45.245', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_192'
Driver info: driver.version: unknown
However the command you have used to initiate the Selenium Grid Node is error prone as it contains both:
platform=MAC
platformName=MAC
Assuming the Selenium Grid Node is being initiated from the Windows 10 box the command should be:
java -Dwebdriver.safari.driver=C:\path\to\safaridriver.exe -jar selenium-server-standalone-3.141.59.jar -role node -hub 10.120.45.245:4444/grid/register -port 5558 -browser "browserName=safari, platform=WINDOWS, maxInstances=1"
Note: Ensure Safari browser is installed within the Windows 10.

Related

Selenium Test not running using test container

My Selenium test is not running with my test container(docker).
Sample Config code
public class ChromeExtension implements BeforeEachCallback {
private BrowserWebDriverContainer browser;
#Override
public void beforeEach(ExtensionContext context) throws Exception {
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--no-sandbox","--headless","--disable-dev-shm-usage",
"--disable-extensions","--verbose","--remote-debugging-port=9222","--disable-gpu");
browser = new BrowserWebDriverContainer()
.withCapabilities(chromeOptions);
browser.start();
WebDriverRunner.setWebDriver(browser.getWebDriver());
}
Dependencies in Build.gradle
testImplementation ('com.codeborne:selenide:5.20.1')
testImplementation 'org.testcontainers:selenium:1.16.3'
testImplementation 'org.testcontainers:junit-jupiter:1.16.3'
Getting Exception Like
Timeout waiting for result with exception
org.rnorth.ducttape.TimeoutException: Timeout waiting for result with exception
at app//org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:54)
at app//org.testcontainers.containers.BrowserWebDriverContainer.getWebDriver(BrowserWebDriverContainer.java:292)
at app//at.magenta.tau.taup.ui.setup.ChromeExtensionTau.beforeEach(ChromeExtensionTau.java:39)
at app//org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeBeforeEachCallbacks$2(TestMethodTestDescriptor.java:163)
at app//org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeBeforeMethodsOrCallbacksUntilExceptionOccurs$6(TestMethodTestDescriptor.java:199)
at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at app//org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeBeforeMethodsOrCallbacksUntilExceptionOccurs(TestMethodTestDescriptor.java:199)
at app//org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeBeforeEachCallbacks(TestMethodTestDescriptor.java:162)
at app//org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:129)
at app//org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:66)
at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at app//org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at java.base#11.0.16.1/java.util.ArrayList.forEach(ArrayList.java:1541)
at app//org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at app//org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at java.base#11.0.16.1/java.util.ArrayList.forEach(ArrayList.java:1541)
at app//org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at app//org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at app//org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
at app//org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
at app//org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:108)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:96)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:75)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:99)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:79)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:75)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
at java.base#11.0.16.1/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base#11.0.16.1/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base#11.0.16.1/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base#11.0.16.1/java.lang.reflect.Method.invoke(Method.java:566)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
at com.sun.proxy.$Proxy5.stop(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker$3.run(TestWorker.java:193)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60)
at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:133)
at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:71)
at app//worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
at app//worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)
Caused by: java.lang.RuntimeException: org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: Could not start a new session. Error while creating session with the driver service. Stopping driver service: Could not start a new session. Response code 500. Message: unknown error: Chrome failed to start: crashed.
(chrome not reachable)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Build info: version: '4.2.1', revision: 'ac4d0fdd4a'
System info: host: '2e6941fb4d93', ip: '172.22.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '5.10.124-linuxkit', java.version: '11.0.15'
Driver info: driver.version: unknown
Build info: version: '4.2.1', revision: 'ac4d0fdd4a'
System info: host: '2e6941fb4d93', ip: '172.22.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '5.10.124-linuxkit', java.version: '11.0.15'
Driver info: driver.version: unknown
Build info: version: '4.2.1', revision: 'ac4d0fdd4a'
System info: host: 'gajendra.khandelwal', ip: 'fe80:0:0:0:4d9:683e:9b45:74a4%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '12.3', java.version: '11.0.16.1'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [--no-sandbox, --headless, --disable-dev-shm-usage, --disable-extensions, --verbose, --remote-debugging-port=9222, --disable-gpu], extensions: []}}], desiredCapabilities=Capabilities {browserName: chrome, goog:chromeOptions: {args: [--no-sandbox, --headless, --disable-dev-shm-usage, --disable-extensions, --verbose, --remote-debugging-port=9222, --disable-gpu], extensions: []}}}]
Capabilities {}
at org.rnorth.ducttape.timeouts.Timeouts.callFuture(Timeouts.java:68)
at org.rnorth.ducttape.timeouts.Timeouts.getWithTimeout(Timeouts.java:43)
at org.testcontainers.containers.BrowserWebDriverContainer.lambda$getWebDriver$1(BrowserWebDriverContainer.java:293)
at org.rnorth.ducttape.unreliables.Unreliables.lambda$retryUntilSuccess$0(Unreliables.java:43)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: Could not start a new session. Error while creating session with the driver service. Stopping driver service: Could not start a new session. Response code 500. Message: unknown error: Chrome failed to start: crashed.
(chrome not reachable)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Build info: version: '4.2.1', revision: 'ac4d0fdd4a'
System info: host: '2e6941fb4d93', ip: '172.22.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '5.10.124-linuxkit', java.version: '11.0.15'
Driver info: driver.version: unknown
Build info: version: '4.2.1', revision: 'ac4d0fdd4a'
System info: host: '2e6941fb4d93', ip: '172.22.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '5.10.124-linuxkit', java.version: '11.0.15'
Driver info: driver.version: unknown
Build info: version: '4.2.1', revision: 'ac4d0fdd4a'
System info: host: 'gajendra.khandelwal', ip: 'fe80:0:0:0:4d9:683e:9b45:74a4%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '12.3', java.version: '11.0.16.1'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [--no-sandbox, --headless, --disable-dev-shm-usage, --disable-extensions, --verbose, --remote-debugging-port=9222, --disable-gpu], extensions: []}}], desiredCapabilities=Capabilities {browserName: chrome, goog:chromeOptions: {args: [--no-sandbox, --headless, --disable-dev-shm-usage, --disable-extensions, --verbose, --remote-debugging-port=9222, --disable-gpu], extensions: []}}}]
Capabilities {}
at app//org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:144)
at app//org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:102)
at app//org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:67)
at app//org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:156)
at app//org.openqa.selenium.remote.TracedCommandExecutor.execute(TracedCommandExecutor.java:51)
at app//org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:551)
at app//org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:246)
at app//org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:162)
at app//org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:144)
at app//org.testcontainers.containers.BrowserWebDriverContainer.lambda$null$0(BrowserWebDriverContainer.java:294)
... 4 more
If you see above My test is not working due to that but if i remove
WebDriverRunner.setWebDriver(browser.getWebDriver());
After removing this it will start working but it should work with this.
Apart from that i am able to see my test container got up when i run test it means my docker container is running properly.
We recenty updated our documentation to reflect the correct way to instantiate the WebDriver:
RemoteWebDriver driver = new RemoteWebDriver(browser.getSeleniumAddress(), new ChromeOptions());
Please give it a try, and else, please share a reproducer. I also noticed that you are using the junit-jupiter module, but you don't use the actual extension in your example. Also, please make sure to use the latest version Testcontainers (1.17.6).

How to use execute selenium automation scripts(java) using safari technology preview?

I wanted some help on running my automation scripts on Safari.
Im running my selenium webdriver scripts on Mac OS(High Sierra) and Safari 11.1.2
I have WebDriver Extension has been added to safari browser and I have enabled the 'Allow Remote Automation'
Here is the way i'm trying to invoke selenium webdriver:
SafariOptions safariOptions = new SafariOptions();
safariOptions.useCleanSession(true);
safariOptions.setUseTechnologyPreview(true);
WebDriver driver = new SafariDriver(safariOptions);
I have also installed Safari technology preview on my machine.
When I run my scripts, it throws below error:
org.openqa.selenium.SessionNotCreatedException: Could not create a session: A browser with name 'safari' version '(null)' could not be found on the system.
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:26:55.152Z'
System info: host: 'Meghas-MacBook-Pro.local', ip: 'fe80:0:0:0:1c74:d309:2877:bd09%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.4', java.version: '1.8.0_171'
Driver info: driver.version: InitiateWebDriver
remote stacktrace:
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:498)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
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.safari.SafariDriver.<init>(SafariDriver.java:78)
at org.openqa.selenium.safari.SafariDriver.<init>(SafariDriver.java:60)
So when I uninstall the Safari technology preview, and change the code to
org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:24147
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:26:55.152Z'
System info: host: 'Meghas-MacBook-Pro.local', ip: 'fe80:0:0:0:1c74:d309:2877:bd09%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.4', java.version: '1.8.0_171'
Driver info: driver.version: InitiateWebDriver
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:92)
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.safari.SafariDriver.<init>(SafariDriver.java:78)
at org.openqa.selenium.safari.SafariDriver.<init>(SafariDriver.java:60)
Inbetween it also said that "Safari driver requires safari 10 running on OSX EL Capitan or greater"
As occurs with other selenium webdrivers you should specify where is the binary of Safari to run it.
System.setProperty("webdriver.safari.driver", "/mypath/binary");
The path usually is /System/Library/CoreServices/SafariSupport.bundle/Contents/MacOS/safaridriver. And do it before your example lines.
And activate the Safari automation:

How to fix “Permission denied to access property "invoke”"?

Code -
Select Gender = new Select(driver.findElement(By.xpath("//select[#id='gender']")));
Gender.selectByValue("Male");
Error -
`Exception in thread "main" org.openqa.selenium.WebDriverException: **Permission denied to access property "invoke"**
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'COMP2-PC', ip: '192.168.1.9', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_91'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{rotatable=false, raisesAccessibilityExceptions=false, appBuildId=20161123182536, version=50.0.1, platform=XP, proxy=Proxy(), command_id=1.0, specificationLevel=0.0, acceptSslCerts=false, processId=2380.0, browserVersion=50.0.1, platformVersion=6.1, XULappId={ec8030f7-c20a-464f-9b0e-13a3a9e97384}, browserName=firefox, takesScreenshot=true, takesElementScreenshot=true, javascriptEnabled=true, platformName=windows_nt}] Session ID: c1e4da76-9f21-45aa-a1b8-f21a9e8dd088
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException
(W3CHttpResponseCodec.java:150)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode
(W3CHttpResponseCodec.java:115)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode
(W3CHttpResponseCodec.java:45)
at org.openqa.selenium.remote.HttpCommandExecutor.execute
(HttpCommandExecutor.java:164)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute
(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute
(RemoteWebDriver.java:637)
at org.openqa.selenium.remote.RemoteWebElement.execute
(RemoteWebElement.java:272)
at org.openqa.selenium.remote.RemoteWebElement.getAttribute
(RemoteWebElement.java:124)
at org.openqa.selenium.support.ui.Select.<init>(Select.java:52)
at AppInformationTest.main(AppInformationTest.java:70) `
While trying to automate (Selecting a dropdown value) with selenium webdriver I ran into this problem.
Tools Versions are*:
Java - 1.8.0_91,
Eclipse - Oxygen Release (4.7.0),
Mozilla Firefox-50.01,
Gecko driver-v0.17.0-win64 ....Please help me to sort out!
It is browser specfic issue , try it with Chrome. Follow this link to see more
Reference Link for your issue

PhantomJS selenium NoSuchElementException

I have created a web crawler with Selenium (using selenium-server-standalone-2.47.1.jar) and phantomJs (phantomjs -v returns 1.9.0 on Ubuntu 14.04). The code was working fine with both with FirefoxDriver and PhantomJSDriver on Windows 10, but only works with FirefoxDriver under Ubuntu 14.04.
Sample code below:
public static void main(String[] args) {
DesiredCapabilities DesireCaps = new DesiredCapabilities();
DesireCaps.setCapability("phantomjs.binary.path", "/usr/lib/phantomjs/phantomjs");
WebDriver driver=new PhantomJSDriver(DesireCaps);
String Url = "https://xxx";
driver.get(Url);
WebElement rootWebElement = driver.findElement(By.id("main"));
List<WebElement> parentElements = rootWebElement.findElements(By.tagName("li"));
//243 , 240 (previous)
for (int i = 106; i < parentElements.size(); i++) {
WebElement href =parentElements.get(i).findElement(By.tagName("z"));
if(href!=null){
Scanner scanner = new Scanner(href.getAttribute("href"));
try {
scanner.parseXML(href.getAttribute("href"));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
If you open the provided URL's source.... you can easily see that the tag with id="main" exists...
Stack Trace:
PhantomJS is launching GhostDriver...
[INFO - 2015-08-13T14:15:57.720Z] GhostDriver - Main - running on port 8677
[INFO - 2015-08-13T14:15:58.361Z] Session [d17a3cc0-41c5-11e5-bedb-6fa39763a2c0] - CONSTRUCTOR - Desired Capabilities: {"phantomjs.binary.path":"/usr/lib/phantomjs/phantomjs"}
[INFO - 2015-08-13T14:15:58.370Z] Session [d17a3cc0-41c5-11e5-bedb-6fa39763a2c0] - CONSTRUCTOR - Negotiated Capabilities: {"browserName":"phantomjs","version":"1.9.0","driverName":"ghostdriver","driverVersion":"1.0.3","platform":"linux-unknown-32bit","javascriptEnabled":true,"takesScreenshot":true,"handlesAlerts":false,"databaseEnabled":false,"locationContextEnabled":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"cssSelectorsEnabled":true,"webStorageEnabled":false,"rotatable":false,"acceptSslCerts":false,"nativeEvents":true,"proxy":{"proxyType":"direct"}}
[INFO - 2015-08-13T14:15:58.371Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created: d17a3cc0-41c5-11e5-bedb-6fa39763a2c0
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Error Message => 'Unable to find element with id 'main''
caused by Request => {"headers":{"Accept-Encoding":"gzip,deflate","Connection":"Keep-Alive","Content-Length":"29","Content-Type":"application/json; charset=utf-8","Host":"localhost:8677","User-Agent":"Apache-HttpClient/4.4.1 (Java/1.7.0_79)"},"httpVersion":"1.1","method":"POST","post":"{\"using\":\"id\",\"value\":\"main\"}","url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/d17a3cc0-41c5-11e5-bedb-6fa39763a2c0/element"}
Command duration or timeout: 281 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 03:03:16'
System info: host: 'Vmbox', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'i386', os.version: '3.19.0-25-generic', java.version: '1.7.0_79'
*** Element info: {Using=id, value=main}
Session ID: d17a3cc0-41c5-11e5-bedb-6fa39763a2c0
Driver info: org.openqa.selenium.phantomjs.PhantomJSDriver
Capabilities [{platform=LINUX, acceptSslCerts=false, javascriptEnabled=true, browserName=phantomjs, rotatable=false, driverVersion=1.0.3, locationContextEnabled=false, version=1.9.0, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=false, browserConnectionEnabled=false, proxy={proxyType=direct}, nativeEvents=true, webStorageEnabled=false, driverName=ghostdriver, applicationCacheEnabled=false, takesScreenshot=true}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:595)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:348)
at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:389)
at org.openqa.selenium.By$ById.findElement(By.java:215)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:340)
at LinkScanner.main(LinkScanner.java:27)
Caused by: org.openqa.selenium.remote.ScreenshotException: Screen shot has been taken
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 03:03:16'
System info: host: 'Vmbox', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'i386', os.version: '3.19.0-25-generic', java.version: '1.7.0_79'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:138)
... 6 more
Caused by: org.openqa.selenium.NoSuchElementException: Error Message => 'Unable to find element with id 'main''
caused by Request => {"headers":{"Accept-Encoding":"gzip,deflate","Connection":"Keep-Alive","Content-Length":"29","Content-Type":"application/json; charset=utf-8","Host":"localhost:8677","User-Agent":"Apache-HttpClient/4.4.1 (Java/1.7.0_79)"},"httpVersion":"1.1","method":"POST","post":"{\"using\":\"id\",\"value\":\"main\"}","url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/d17a3cc0-41c5-11e5-bedb-6fa39763a2c0/element"}
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 03:03:16'
System info: host: 'Vmbox', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'i386', os.version: '3.19.0-25-generic', java.version: '1.7.0_79'
Driver info: driver.version: unknown
Post my comment as answer :)
You need to install PhantomJS 1.9.8 from https://bitbucket.org/ariya/phantomjs/downloads

Issue launching Phantomjs Selenium Web Driver

I'm using phantom.js driver for selenium in some java code.
It's a large project so i'll only copy what I think is the relevant code.
I had it working fine with the firefox driver.
I instantiate it here:
Capabilities caps = new DesiredCapabilities();
((DesiredCapabilities) caps).setJavascriptEnabled(true);
((DesiredCapabilities) caps).setCapability("takesScreenshot", true);
((DesiredCapabilities) caps).setCapability("timeoutInSeconds", 20);
((DesiredCapabilities) caps).setCapability(
PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
"/Applications/phantomjs-2.0.0-macosx/bin/phantomjs"
);
WebDriver driver = new PhantomJSDriver(caps);
driver.get(base_url+searchQuery.urlString());
Then when I run the program I get a list of errors:
SEVERE: org.apache.commons.exec.ExecuteException: Process exited with an error: 137 (Exit value: 137)
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.46.0', revision: '87c69e2', time: '2015-06-04 16:17:10'
System info: host: 'Dannys-MacBook-Pro.local', ip: '10.104.0.84', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.3', java.version: '1.7.0_79'
Driver info: driver.version: PhantomJSDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:242)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:128)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:141)
at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:115)
at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:104)
at scrape.MyFreeMp3Adapter.performScrape(MyFreeMp3Adapter.java:63)
at Main.main(Main.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '2.46.0', revision: '87c69e2', time: '2015-06-04 16:17:10'
System info: host: 'Dannys-MacBook-Pro.local', ip: '10.104.0.84', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.3', java.version: '1.7.0_79'
Driver info: driver.version: PhantomJSDriver
at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:170)
at org.openqa.selenium.phantomjs.PhantomJSCommandExecutor.execute(PhantomJSCommandExecutor.java:78)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:578)
... 12 more
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:36316/status] to be available after 20006 ms
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:104)
at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:167)
... 14 more
Caused by: com.google.common.util.concurrent.UncheckedTimeoutException: java.util.concurrent.TimeoutException
at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:143)
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:79)
... 15 more
Caused by: java.util.concurrent.TimeoutException
at java.util.concurrent.FutureTask.get(FutureTask.java:201)
at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:130)
... 16 more
Its seems like it can't get the driver server to start.

Categories