seleniumbase / SeleniumBase

📊 Blazing fast Python framework for web crawling, scraping, testing, and reporting. Supports pytest. Stealth abilities: UC Mode and CDP Mode.
https://seleniumbase.io
MIT License
5.44k stars 983 forks source link

Could not start a new session. Response code 500. Message: session not created: Chrome failed to start: exited normally. (session not created: DevToolsActivePort file doesn't exist) #3160

Closed yash2880 closed 2 months ago

yash2880 commented 2 months ago

package pcm;

import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.time.Duration; import java.util.List; import java.util.Properties; import org.openqa.selenium.chrome.ChromeOptions; import org.apache.commons.compress.compressors.FileNameUtil; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.time.StopWatch; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.Keys; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.support.PageFactory; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; // import com.github.dockerjava.core.dockerfile.DockerfileStatement.Add; import com.relevantcodes.extentreports.ExtentReports; import com.relevantcodes.extentreports.ExtentTest; import com.relevantcodes.extentreports.LogStatus;

public class PCM{ public static ExtentReports extent; public static ExtentTest show; public static WebDriver driver; public static WebDriverWait wait;

@Test
public void Pcm() throws IOException, InterruptedException { Properties credential = new Properties(); credential.load(new FileInputStream("./WSO2Test.properties")); String tenantValue = System.getenv("Tenant"); String branchName = System.getenv("BRANCH_NAME"); System.out.println("Branch Name: " + branchName); String buildNumber = System.getenv("BUILD_NUMBER"); String reportDirPath = "C:\Users\hvxqa01\Documents\Sample\QA-Automation\AWSTEST\Basic-Automation\Reports\" + buildNumber; File reportDir = new File(reportDirPath); reportDir.mkdirs();

extent = new ExtentReports(reportDirPath + "\\Report.html", true);
show = extent.startTest("PCM Login");
    ChromeOptions options = new ChromeOptions();
    options.setBinary("/usr/bin/google-chrome");
    options.addArguments("--headless"); // Run Chrome in headless mode
    options.addArguments("--no-sandbox"); // Required if running as root
    options.addArguments("--disable-dev-shm-usage"); // To avoid shared memory issues
    options.addArguments("--disable-gpu"); // Optional: Disable GPU acceleration (useful for headless mode)
    options.addArguments("--disable-software-rasterizer");
    options.addArguments("--window-size=1920,1080");
    options.addArguments("--verbose");
    options.addArguments("--disable-setuid-sandbox");
    options.addArguments("--remote-debugging-port=9222"); // Enable remote debugging
    System.setProperty("Webdriver.chrome.driver", "/usr/local/bin/chromedriver");
    //WebDriver driver = new ChromeDriver(options); 
    driver = new ChromeDriver();
    driver.manage().window().maximize();
    StopWatch stopwatch = new StopWatch("Facility");
stopwatch.start();
wait = new WebDriverWait(driver, Duration. ofMinutes(2));
show.log(LogStatus.INFO, "Launching the PCM-Test Portal");
driver.get(credential.getProperty("PCMURL"));
wait.until(ExpectedConditions.presenceOfElementLocated(By.name("username"))).sendKeys(credential.getProperty("AdminUsername"));
driver.findElement(By.xpath("//*[text() = \"Next\"]")).click();

Unable to run this script in ubuntu but it is working in windows perfectly!

Getting the below error

org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: session not created: Chrome failed to start: exited normally. (session not created: DevToolsActivePort file doesn't exist) (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

  1. Both the browser and chromedriver versions are same

Kindly help on this issue

mdmintz commented 2 months ago

This area is for questions about SeleniumBase: A Python framework. (Not Java)

For general Selenium questions, see: https://github.com/SeleniumHQ/selenium/.