【问题标题】:Running Selenium on jenkins takes my local chromedriver在 jenkins 上运行 Selenium 需要我本地的 chromedriver
【发布时间】:2021-04-29 00:13:43
【问题描述】:

我正在尝试通过 Jenkins 使用 selenium 测试我们的网站,以便每天测试每个功能。

问题是 Jenkins 失败了,因为他试图用我的本地路径获取 chromedriver,但没有本地路径。

错误信息:

[ERROR] main(at.s2gplus.selenium.TestPromoteToAdmin) 已用时间: 0.006 秒

代码:

public class TestPromoteToAdmin {
    
WebDriver driver = new ChromeDriver();


@Test
public void main() {


    
    driver.get("https://192.168.1.45:8080/");
    WebDriverWait wait = new WebDriverWait(driver, 90);
    
    driver.manage().window().maximize();

    driver.findElement(By.id("details-button")).click();
    driver.findElement(By.id("proceed-link")).click();
    driver.findElement(By.id("home-open-sign-in")).click();
    driver.findElement(By.id("login-username")).sendKeys("tester");
    driver.findElement(By.id("login-password")).sendKeys("wurst01");
    driver.findElement(By.id("login-action")).click();
    
    wait.until(ExpectedConditions.elementToBeClickable(By.id("left-menu-room-title-add-action"))).click();
    driver.findElement(By.id("create-room-name-input")).sendKeys("Selenium Admin test");
    driver.findElement(By.id("create-room-description-input")).sendKeys("Selenium Test");
    driver.findElement(By.id("create-room-save")).click();
    
    JavascriptExecutor js = (JavascriptExecutor) driver;
    WebElement roomToClick = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[contains(text(), 'Selenium Admin test')]")));
    js.executeScript("arguments[0].scrollIntoView();", roomToClick);
    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    wait.until(ExpectedConditions.elementToBeClickable(roomToClick)).click();
    wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[contains(@id, 'left-roomlist-settingsicon')]"))).click();
    WebElement addMemberBtn = wait.until(ExpectedConditions.elementToBeClickable(By.id("room-settings-add-user")));
    addMemberBtn.click();
            
     
    WebElement checkBox = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("label[for='990bd6a8-62af-48c5-89a5-33019483c91f'")));//("cb732433-eae9-434b-96da-b4d5a499208c"));
    checkBox.click();
    WebElement addBtn = driver.findElement(By.id("room-settings-add-button"));
    addBtn.click();
    WebElement saveUserBtn = driver.findElement(By.id("room-settings-save"));
    saveUserBtn.click();
    
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    
    wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[contains(@id, 'left-roomlist-settingsicon')]"))).click();
    
    wait.until(ExpectedConditions.elementToBeClickable(By.id("general-menu-list-item-settings"))).click();
    wait.until(ExpectedConditions.elementToBeClickable(By.id("room-settings-context-change-role-to-moderator"))).click();
    
    wait.until(ExpectedConditions.elementToBeClickable(By.id("general-menu-list-item-settings"))).click();
    wait.until(ExpectedConditions.elementToBeClickable(By.id("room-settings-context-change-role-to-admin"))).click();
    driver.findElement(By.id("room-settings-save")).click();
    driver.findElement(By.id("top-logout")).click();

    driver.findElement(By.id("home-open-sign-in")).click();
    driver.findElement(By.id("login-username")).sendKeys("tester01");
    driver.findElement(By.id("login-password")).sendKeys("wurst02");
    driver.findElement(By.id("login-action")).click();
    
    roomToClick = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[contains(text(), 'Selenium Admin test')]")));
    js.executeScript("arguments[0].scrollIntoView();", roomToClick);
    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    wait.until(ExpectedConditions.elementToBeClickable(roomToClick)).click();
    
    WebElement roomAdmin = driver.findElement(By.xpath("//span[contains(text(), 'Selenium Admin test')]"));
    String room = roomAdmin.getText();
    assertTrue(room, true);
    
    wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[contains(@id, 'left-roomlist-settingsicon')]"))).click();
    wait.until(ExpectedConditions.elementToBeClickable(By.id("meeting-settings-open-close-room-modal"))).click();
    wait.until(ExpectedConditions.elementToBeClickable(By.id("meeting-settings-close-room-confirm"))).click();

}

@BeforeTest
public void beforeTest() {
ChromeOptions options = new ChromeOptions();
options.setHeadless(true);
options.setAcceptInsecureCerts(true);
driver = new ChromeDriver(options);  
}       
@AfterTest
public void afterTest() {
    driver.quit();          
}       
}

第 36 行在driver.get("https://192.168.1.45:8080/"); 上面,但我早就删除了它

【问题讨论】:

    标签: java jenkins selenium-webdriver


    【解决方案1】:

    在 Jenkins 中安装 Selenium Grid 插件,使用以下代码进行节点设置。在以下代码中更新 selenium server 独立 jar 版本和浏览器版本。

    java -jar selenium-server-standalone-x.xx.x.jar - 
    Dwebdriver.chrome.driver="C:\yourpath\chromedriver.exe" -role node -hub 
    http://localhost:4444/grid/register -browser "browserName=internet 
    explorer,version=xx,platform=WINDOWS" -browser 
    "browserName=chrome,version=xx,platform=WINDOWS" 
    

    【讨论】:

      【解决方案2】:

      请更新下面的代码行开始

          
      WebDriver driver = null;
      
      
      @Test
      public void main() {
      
        System.setProperty("webdriver.chrome.driver","E:\\drivers\\ChromeDrivers\\85\\chromedriver.exe");
          driver = new ChromeDriver();
          driver.get("https://192.168.1.45:8080/");
          WebDriverWait wait = new WebDriverWait(driver, 90);
          
          driver.manage().window().maximize(); ```
      

      【讨论】:

      • 请在您的框架中创建一个驱动程序文件夹并保留 chrome 驱动程序并将 chromedriver 传递到系统属性 System.setProperty("webdriver.chrome.driver","E:\\drivers\\ChromeDrivers\\85 \\chromedriver.exe");
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-17
      • 2013-07-26
      • 2016-11-29
      • 2013-03-23
      • 2014-10-07
      • 2017-04-24
      相关资源
      最近更新 更多