【问题标题】:Start Selenium test cases using jenkins使用 jenkins 启动 Selenium 测试用例
【发布时间】:2013-04-04 18:16:43
【问题描述】:

我已经使用 selenium webdriver 准备了一个测试用例,我使用 MSTEST 在本地运行,它工作正常,现在我想将我的测试用例移动到 JENKINS,当我从 JENKINS 运行时,它显示 Starting execution... 并且它不止15 mnts 仍然是相同的状态,所以我必须手动停止它。

这是我的控制台输出:

Started by user anonymous
Started by user anonymous
Building in workspace D:\Jenkins\jobs\Selenium_Script\workspace
[workspace] $ cmd /c call C:\Users\XXXXXXX\AppData\Local\Temp\hudson4765437871038045571.bat

D:\Jenkins\jobs\SelScript\workspace>call "D:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\mstest" /testcontainer:D:\Sel\EmployeeTest\test.emp.admin.dll 
Microsoft (R) Test Execution Command Line Tool Version 10.0.30319.1
Copyright (c) Microsoft Corporation. All rights reserved.

Loading D:\Sel\EmployeeTest\test.emp.admin.dll...
Starting execution...

Build was aborted
Finished: ABORTED

我想在 Jenkins 上执行测试用例并检查执行结果

这是我正在使用的代码,以防万一。

这是我用来实例化驱动程序的东西,我必须使用RemoteDriver吗?

public static IWebDriver GetDriver()
        {
            string _url = new Uri(Common.Url).DnsSafeHost.ToString(); 

            switch (Common.BrowserSelected)
            {
                case "ff":
                    FirefoxProfile profile = new FirefoxProfile();
                    profile.SetPreference("network.http.phishy-userpass-length", 255);
                    profile.SetPreference("network.automatic-ntlm-auth.trusted-uris", _url);
                    drv = new FirefoxDriver(profile);
                    break;
                case "ie":
                    var options = new InternetExplorerOptions();
                    options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
                    DesiredCapabilities capabilities = new DesiredCapabilities();
                    capabilities.SetCapability(CapabilityType.AcceptSslCertificates, true);
                    drv = new InternetExplorerDriver(options);
                    break;
                case "chrome":
                    //_driver = new ChromeDriver();
                    break;
            }
            return drv;
        }

【问题讨论】:

    标签: jenkins webdriver selenium-webdriver remotewebdriver


    【解决方案1】:

    您可以在 Jenkins 的 Build 部分运行您的 Selenium 脚本。

    点击Add Build Step并选择Execute Shell,在那里你可以直接运行你的命令,就像在Linux环境中输入一样。

    所有这一切都假设您在 Linux 环境中运行 Jenkins。

    @我必须使用RemoteDriver吗? 取决于您是否安装了 xvfb 以在无头模式下运行测试? 如果不是,那么可以,您可以将测试重定向到在 windows/mac 机器上远程运行。

    更新

    如果你有一台windows机器,你不需要xvfb。所以别提了。

    用于构建项目的 Shell 脚本(默认为 sh,但这是可配置的)。该脚本将以工作区作为当前目录运行。输入你的 shell 脚本的内容。如果您的 shell 脚本没有像 #!/bin/sh 这样的标题行,那么将使用系统范围内配置的 shell,但您也可以使用标题行以另一种语言编写脚本(例如 #!/bin/perl ) 或控制 shell 使用的选项。 默认情况下,将使用“-ex”选项调用 shell。因此,所有命令在执行之前都会打印出来,如果任何命令以非零退出代码退出,则构建将被视为失败。同样,添加 #!/bin/... 行以更改此行为。

    作为最佳实践,请尽量不要在此处放置较长的 shell 脚本。相反,请考虑在 SCM 中添加 shell 脚本,然后简单地从 Jenkins 调用该 shell 脚本(通过 bash -ex myscript.sh 或类似的东西),以便您可以跟踪 shell 脚本中的更改。

    例子-

    你可以像这样运行 ruby​​ 命令

    ruby testscripts.rb
    

    或者像这样的shell脚本

    ./testscripts.sh
    

    【讨论】:

    • 我使用的是windows环境,假设我会像这样执行shellD:\Jenkins\jobs\SelScript\workspace>call "D:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\mstest" /testcontainer:D:\Sel\EmployeeTest\test.emp.admin.dll
    • 什么是 xvfb/headless?和我一起裸露,我是新手
    • @Amey:我通过 testng.xml 让 selenium webdriver 脚本在 Windows 中运行良好。我的 Jenkins 服务器在 Linux 中运行。如何调用 testng.xml ?
    【解决方案2】:

    Jenkins 超级简单。只需这样做:

      1.  Allow Jenkins to check-out your code into the Jenkins workspace.
      2.  Navigate to that workspace on your Windows computer and manually run
          the tests by executing the script that starts them.
    

    通过这样做,詹金斯暂时不在画面中,因此不再是您的问题的原因。然后,您可以专注于真正的实际问题是什么。解决问题后,将更改检查到源代码存储库中,然后再次运行 Jenkins 构建并尝试再次手动运行。如果这也有效,那么最后,您就可以在 Jenkins 中设置构建任务来运行您的测试了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-04
      • 2011-11-17
      • 2015-07-02
      • 2012-02-01
      相关资源
      最近更新 更多