简体   繁体   English

Phpunit和詹金斯

[英]Phpunit and Jenkins

I have a PHP project written in PHPUnit using Selenium. 我有一个使用Selenium用PHPUnit编写的PHP项目。

The project is structured as below: PHPProjectName 该项目的结构如下:PHPProjectName

  • Source Files 源文件
    • (doesn't contain anything) (不包含任何内容)
  • Selenium Test Files 硒测试文件
    • contains all my selenium test php files - extending the class PHPUnit_Extensions_SeleniumTestCase 包含我所有的硒测试php文件-扩展类PHPUnit_Extensions_SeleniumTestCase
  • Include Path 包含路径
    • c:\\program files\\PHP c:\\ program files \\ PHP
    • c:\\program files\\PHP\\PEAR\\PHPUnit c:\\ program files \\ PHP \\ PEAR \\ PHPUnit

I then run start the Selenium server manually by running java -jar selenium-server-standalone-2.24.1.jar 然后,我通过运行java -jar selenium-server-standalone-2.24.1.jar来手动启动Selenium服务器。

The php script to execute all my selenium test php files works fine. 执行我所有的硒测试php文件的php脚本工作正常。

But now I want to use Jenkins as a test management tool to build and execute my PHPunit tests in this folder. 但是现在我想使用Jenkins作为测试管理工具来在此文件夹中构建和执行我的PHPunit测试。 I guess the steps are: 我猜这些步骤是:

  • Install Jenkins 安装詹金斯
  • Write a build script for the PHPunit tests 编写用于PHPunit测试的构建脚本
  • Execute the build script through Jenkins 通过詹金斯执行构建脚本

Are the steps correct? 步骤正确吗? Has anyone done or know how to set this up? 有没有人做过或知道如何设置?

Thanks very much, 非常感谢,

I have done this many times with various platforms. 我已经在各种平台上做了很多次。 Your steps are generally correct and should work, however managing the server is not always so simple. 您的步骤通常是正确的,应该可以,但是管理服务器并不总是那么简单。 The Selenium RC server gets unstable if left open for too long, so you will have to manage it somehow. 如果Selenium RC服务器打开时间过长,它将变得不稳定,因此您将不得不以某种方式对其进行管理。

You could set up a second Jenkins job which runs once or twice a day to reset your server. 您可以设置第二个Jenkins作业,该作业每天运行一两次,以重置服务器。 The better option however would be to write a simple test framework which closes any open servers and then launches a new server instance before running the tests. 但是,更好的选择是编写一个简单的测试框架,该框架将关闭所有打开的服务器,然后在运行测试之前启动新的服务器实例。 You could also use a cron job to reset the server of course, but if you have Jenkins installed it will be easier to do this via a jenkins job. 当然,您也可以使用cron作业来重置服务器,但是如果您安装了Jenkins,则通过jenkins作业更容易进行此操作。

The best option of course is to switch to Webdriver, but that could take some work depending on how complex your tests are. 最好的选择当然是切换到Webdriver,但这可能要花一些时间,具体取决于测试的复杂程度。

We have a similar setup to what you describe. 我们有与您描述类似的设置。 We have Jenkins run a job to restart the Selenium server periodically: 我们让詹金斯(Jenkins)运行作业以定期重新启动Selenium服务器:

#!/bin/bash
# startselenium.sh: Start Selenium up and also start headless screen.
Xvfb :99 -ac &
export DISPLAY=:99 
java -jar /opt/selenium/selenium-server-standalone-2.19.0.jar &

Sebastian Bergmann maintains a bunch of templates for using Jenkins with PHP here: http://jenkins-php.org/ 塞巴斯蒂安·伯格曼(Sebastian Bergmann)维护了大量用于在PHP上使用Jenkins的模板: http : //jenkins-php.org/

Included is the necessary Ant script to run PHPUnit (which is really simple and just calls PHPUnit): 包括了运行PHPUnit所需的Ant脚本(这确实很简单,仅调用PHPUnit):

<target name="phpunit" description="Run unit tests with PHPUnit">
    <exec executable="phpunit" failonerror="true"/>
</target>

And the necessary 'phpunit.xml' file: 和必要的“ phpunit.xml”文件:

<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="tests/bootstrap.php"
    backupGlobals="false"
    backupStaticAttributes="false"
    strict="true"
    verbose="true">

    <testsuites>
        <testsuite name="ProjectName">
            <directory suffix="Test.php">tests/unit/</directory>
            <directory suffix="Test.php">tests/integration/</directory>
        </testsuite>
    </testsuites>

    <logging>
        <log type="coverage-html" target="build/coverage" title="BankAccount"
            charset="UTF-8" yui="true" highlight="true"
        lowUpperBound="35" highLowerBound="70"/>
        <log type="coverage-clover" target="build/logs/clover.xml"/>
        <log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false"/>
    </logging>

    <filter>
        <whitelist addUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">src</directory>
            <exclude>
                <file>src/bootstrap.php</file>
            </exclude>
        </whitelist>
    </filter>

</phpunit>

You have to install the selenium plugin in jenkins, then a selenium server will automatically start on jenkins, which will create a hub. 您必须在jenkins中安装selenium插件,然后selenium服务器将自动在jenkins上启动,这将创建一个中心。 Now on the client you have to start a node which connects to this hub. 现在,在客户端上,您必须启动一个连接到该集线器的节点。

Note : The jenkins selenium server is always the same version as the selenium plugin from jenkins. 注意 :jenkins硒服务器始终与jenkins的硒插件版本相同。 So if the selenium plugins name is selenium plugin 3.1.0 then it runs on selenium server 3.1.0. 因此,如果selenium插件名称是selenium插件3.1.0,则它将在selenium服务器3.1.0上运行。

After installing the jenkins selenium plugin, then you can find a new option for selenium grid, click on it and you will get more informations: 安装jenkins硒插件后,您可以找到硒网格的新选项,单击它,您将获得更多信息:

在此处输入图片说明

在此处输入图片说明

Now you have to start a jenkins selenium standalone server like this: 现在,您必须启动一个jenkins硒独立服务器,如下所示:

Windows (create a .bat file with the following content and execute it, change relevant parts accordingly): Windows(创建具有以下内容的.bat文件并执行,相应地更改相关部分):

start java -jar -Dwebdriver.gecko.driver="C:\Webdrivers\GeckoDriver\geckodriver.exe" -Dwebdriver.chrome.driver="C:\Webdrivers\ChromeDriver\chromedriver.exe" selenium-server-standalone-<VERSION>.jar -role node -hub http://<YOUR_JENKINS_MACHINE_IP>:<PORT>/grid/register

In my case, I used: 就我而言,我使用了:

start java -jar -Dwebdriver.gecko.driver="C:\Webdrivers\GeckoDriver\geckodriver.exe" -Dwebdriver.chrome.driver="C:\Webdrivers\ChromeDriver\chromedriver.exe" selenium-server-standalone-3.1.0.jar -role node -hub http://172.25.201.100:4444/grid/register

Make sure to correct the paths to geckodriver and chromedriver to their actual location. 确保将geckodriver和chromedriver的路径更正为它们的实际位置。

Now the node should connect to the hub and you can start your tests. 现在,该节点应连接到集线器,您可以开始测试了。

More infos: https://github.com/SeleniumHQ/selenium/wiki/Grid2 更多信息: https : //github.com/SeleniumHQ/selenium/wiki/Grid2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM