I am writing a simple code where I want to connect to selenium from other container.
version: '3.8'
networks:
web:
external: true
driver: bridge
services:
chrome:
image: selenium/standalone-chrome:latest
hostname: chrome
networks:
- web
privileged: true
shm_size: 2g
ports:
- "4444:4444"
framework:
build: .
networks:
- web
depends_on:
- chrome
ports:
- "3306:3306"
- "80:80"
Simple class file which I am using to make the connect
package docker.chrome.mavendocker;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.BrowserType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.Test;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
/**
* Hello world!
*
*/
public class App {
@Test
public void testApp() throws MalformedURLException, InterruptedException {
DesiredCapabilities cap=new DesiredCapabilities();
cap.setBrowserName(BrowserType.CHROME);
cap.setAcceptInsecureCerts(true);
//ChromeOptions handlingSSL = new ChromeOptions();
//handlingSSL.setAcceptInsecureCerts(true);
//WebDriver driver = new RemoteWebDriver(handlingSSL);
//WebDriver driver = new RemoteWebDriver(handlingSSL);
WebDriver driver=new RemoteWebDriver(new URL("http://chrome:4444/wd/hub"), cap);
driver.get("https://someurl");
//driver.get("https://www.google.com/");/
System.out.println("Title of the page:"+driver.getTitle());
Thread.sleep(30000);
driver.findElement(By.id("searchTerm")).sendKeys("Milk");
Thread.sleep(5000);
driver.findElement(By.xpath("//*[@id='btnSearch']")).click();
Thread.sleep(15000);
driver.quit();
}
}
one more point I'm noticing is that I am able to successfully connect to container by curl, telnet ping. but I am not able to connect from the test.
question from:
https://stackoverflow.com/questions/65878350/not-able-to-connect-to-selenium-chrome-while-setting-up-docker-in-compose-file 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…