0

我在 Ubuntu 上。Chrome 似乎打开了一秒钟,然后崩溃了。所以,我基本上看到了 chrome 的闪光,然后我在控制台中收到了这条消息:

“org.openqa.selenium.WebDriverException:未知错误:Chrome 无法启动:崩溃。(chrome 无法访问)(从 chrome 位置 /usr/bin/google-chrome 开始的进程不再运行,因此 ChromeDriver 假设 Chrome已崩溃。)构建信息:版本:'3.141.59',修订:'e82be7d358',时间:'2018-11-14T08:17:03'”

这就是我设置它的方式

WebDriverManager.chromedriver().setup();
ChromeOptions options = new ChromeOptions();
options.addArguments("--no-sandbox"); 
options.addArguments("--disable-dev-shm-usage"); 
driver = new ChromeDriver(options);

这是我正在运行的课程:

package com.noorteck.qa.api;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

import com.noorteck.qa.pages.CommonElementPage;
import com.noorteck.qa.pages.JobTitlesPage;
import com.noorteck.qa.pages.LoginPage;
import com.noorteck.qa.pages.NavigateToPage;
import com.noorteck.qa.utils.CommonUI;
import com.noorteck.qa.utils.ReadPropertyData;

public class DBDemo extends CommonUI {

    public static void main(String[] args) throws SQLException, ClassNotFoundException {

        String url = "jdbc:mysql://localhost:3306";
        String userName = "root";
        String password = "Negro434";
        String exStatus;
        String failedReason = "NULL";

        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection con = DriverManager.getConnection(url, userName, password);

        Statement stm = con.createStatement();
        prop = ReadPropertyData.getProperties(configFilePath);

        openBrowser(prop.getProperty("browser"));
        navigate(prop.getProperty("url"));

        loginObj = new LoginPage();
        jobTitlesObj = new JobTitlesPage();
        navToPageObj = new NavigateToPage();
        commonElObj = new CommonElementPage();

        loginObj.login();
        navToPageObj.navigateToJobTitles();

        jobTitlesObj.clickAddIcon();
        jobTitlesObj.enterJobTitleName("Dev 0");
        jobTitlesObj.enterJobDescription("SDETTTTTT");
        commonElObj.clickSaveButton();

        String actualSuccessMessage = commonElObj.getSuccessMessage();
        String expectedSuccessMessage = "Successfully Saved";

        System.out.println(actualSuccessMessage);

        boolean outcome = actualSuccessMessage.equalsIgnoreCase(expectedSuccessMessage);

        if (outcome == true) {
            exStatus = "PASSED";
        } else {
            exStatus = "FAILED";
            failedReason = "[EXP:" + expectedSuccessMessage + "] -- [ACT: " + actualSuccessMessage + "]";
        }

        String query = "INSERT INTO walmart.testresults (project_name, sprint_number, us_number, region, status, failure_reason, date)"
                + "VALUES ('ntk', 404, 'ntk-404', 'scrum', '" + exStatus + "', '" + failedReason + "', '2021-04-11');";

        stm.executeUpdate(query);

        System.out.println(exStatus);
        System.out.println(query);
        apiSoftAssert.assertTrue(outcome);

    }

}

我也玩过不同的选项组合。还安装了铬,它做同样的事情,打开几分之一秒然后关闭。

options.addArguments("--no-sandbox"); 
//options.setBinary("/snap/bin/chromium");
//options.addArguments("--disable-dev-shm-usage"); 
//options.addArguments("--headless"); 

我从终端运行 ./google-chrome 并打开正常。有任何想法吗。谢谢

4

0 回答 0