使用CI工具Jenkins运行脚本时不会触发chrome

时间:2017-01-24 03:49:21

标签: jenkins

我正在学习使用硒与詹金斯, 准备一个脚本 “”@Test

public void helloJenkin()
{
    System.out.println("hello Jenin");
    String path="D:\\Selenium\\ChromeDriver\\chromedriver_win32\\chromedriver.exe";
    System.setProperty("webdriver.chrome.driver",path );
    WebDriver driver=new ChromeDriver();
    driver.manage().window().maximize();
    WebDriverWait wait=new WebDriverWait(driver,5000);
    driver.navigate().to("https://www.google.co.in/");
    System.out.println(driver.getTitle());
    driver.quit();
}"""

使用命令提示符运行时,此脚本运行完全正常。 但是在使用Jenkins时,我收到了以下错误

Started by user admin
Building in workspace C:\Users\jeetendra\Desktop\jenkinsDemo
[jenkinsDemo] $ cmd /c call C:\WINDOWS\TEMP\hudson7643820465261394286.bat

C:\Users\jeetendra Tiwari\Desktop\jenkinsDemo>run.bat

C:\Users\jeetendra Tiwari\Desktop\jenkinsDemo>java -cp bin;lib/* org.testng.TestNG testng.xml 
[TestNG] Running:
  C:\Users\jeetendra Tiwari\Desktop\jenkinsDemo\testng.xml

hello Jenin
Starting ChromeDriver 2.25.426923 (03903626326234d6eb0d5d0934646634634934aab9eed) on port 12185
Only local connections are allowed.
===============================================
Suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================

Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE

请你帮忙解释为什么没有触发镀铬。

2 个答案:

答案 0 :(得分:0)

首先验证在Jenkins运行的服务器上安装了chrome。 在同一服务器上验证chrome驱动程序的路径。

您可以在Jenkins上安装Xvnc插件,它会显示浏览器是否打开,您可以看到在该jenkins服务器上运行的实际测试用例。

要添加插件,请按照步骤

进行操作
  1. Jenkins>管理Jenkins>管理插件
  2. 单击“可用选项卡”
  3. 搜索Xvnc
  4. 点击“不重启时安装”按钮

答案 1 :(得分:0)

只需尝试在您的Selenium代码中添加try and catch块,例如- ---------示例-------------

公共类Chrome enter image description here {

@Test
public void sampleApp() 
{

    try
    {
        WebDriver driver;

        System.setProperty("webdriver.chrome.driver","C:\\Users\\workspace\\Jenkins_Selenium\\ChromeLaunch\\driver\\chromedriver.exe");

        driver = new ChromeDriver();

        System.out.println("Hello Google...");
        System.out.println("Successfully Launched the browser...");
        driver.get("http:\\localhost:8080");
        System.out.println("Successfully Executed the URL...");
        driver.quit();
        System.out.println("Successfully Executed The flow...");
    }
    catch(Exception e)
    {
        System.out.println("Successfully Executed with exceptions..");
        System.out.println(e);
    }
}

这可能有效,但是如果您的测试用例仍然失败,则还需要做一件事。当您在公司网络中的云计算机上执行Jenkins&Selenium并需要进行身份验证时,通常会完成它,因为它可能会阻止,所以你要做的是-

只需按Windows + R键并键入services.msc,您的桌面上运行的所有服务都将打开,只需转到jenkins 就像在Capture1图像中一样,右键单击并像在Capture2图像中一样打开属性,然后转到“登录”选项卡,在其中选择(此帐户),然后通过浏览名称和密码并确认密码来提供凭据,然后给您的凭据按确定,现在再次回到“常规”选项卡,停止并启动詹金斯服务。 现在返回您的jenkins网址,并尝试使用jenkins执行Selenium脚本。

-----希望这会有所帮助-----