Selenium Python配置Jenkins以运行构建。我的构建失败了

时间:2015-09-12 20:54:31

标签: python-2.7 selenium jenkins selenium-webdriver

我正在尝试配置Jenkins来构建我的Selenium Webdriver Python代码。 当我单击Build Now时,它会失败 控制台输出显示以下内容:

Building in workspace C:\Program Files\Jenkins\workspace\ClearCore
[ClearCore] $ cmd /c call C:\Windows\TEMP\hudson6133135491793466847.bat

C:\Program Files\Jenkins\workspace\ClearCore>copy E:\RL Fusion\projects\Jenkins sample\ClearCore501\TestCases\*.py 
The system cannot find the file specified.

C:\Program Files\Jenkins\workspace\ClearCore>python smoketests.py 
python: can't open file 'smoketests.py': [Errno 2] No such file or directory

C:\Program Files\Jenkins\workspace\ClearCore>exit 2 
Build step 'Execute Windows batch command' marked build as failure
Recording test results
ERROR: Publisher 'Publish JUnit test result report' failed: No test report files were found. Configuration error?
Finished: FAILURE

在PyCharm中我有一个smoketests.py文件,如下所示:

    import unittest
from xmlrunner import xmlrunner
from TestCases.LoginPage_TestCase import LoginPage_TestCase
from TestCases.AdministrationPage_TestCase import AdministrationPage_TestCase
from TestCases.DataConfigurationPage_TestCase import DataConfigurationPage_TestCase

login_tests = unittest.TestLoader().loadTestsFromTestCase(LoginPage_TestCase)
admin_tests = unittest.TestLoader().loadTestsFromTestCase(AdministrationPage_TestCase)
dataconf_tests = unittest.TestLoader().loadTestsFromTestCase(DataConfigurationPage_TestCase)

smoke_tests = unittest.TestSuite([login_tests, admin_tests, dataconf_tests])

xmlrunner.XMLTestRunner(verbosity=2, output='test-reports').run(smoke_tests)

我有一个test_HTMLRunner.py,如下所示:

import unittest
import HTMLTestRunner
import os
from TestCases.LoginPage_TestCase import LoginPage_TestCase
from TestCases.AdministrationPage_TestCase import AdministrationPage_TestCase
from TestCases.DataConfigurationPage_TestCase import DataConfigurationPage_TestCase

# get the directory path to output report file
result_dir = os.getcwd()

login_tests = unittest.TestLoader().loadTestsFromTestCase(LoginPage_TestCase)
admin_tests = unittest.TestLoader().loadTestsFromTestCase(AdministrationPage_TestCase)
dataconf_tests = unittest.TestLoader().loadTestsFromTestCase(DataConfigurationPage_TestCase)

smoke_tests = unittest.TestSuite([login_tests, admin_tests, dataconf_tests])

# open the report file
outfile = open(result_dir + "\TestReport.html", "w")

# configure HTMLTestRunner options
runner = HTMLTestRunner.HTMLTestRunner(stream=outfile,
                                       title='Test Report',
                                       description='LADEMO create a basic project test')

# run the suite using HTMLTestRunner
runner.run(smoke_tests)

我有一个suite.py如下:

    import sys
import unittest
import HTMLTestRunner
import os
import unittest
import AdministrationPage_TestCase
import LoginPage_TestCase
import DataConfigurationPage_TestCase

class Test_Suite(unittest.TestCase):

    def test_main(self):

        # suite of TestCases
        self.suite = unittest.TestSuite()
        self.suite.addTests([
            unittest.defaultTestLoader.loadTestsFromTestCase(LoginPage_TestCase.LoginPage_TestCase),
            unittest.defaultTestLoader.loadTestsFromTestCase(AdministrationPage_TestCase.AdministrationPage_TestCase),
            unittest.defaultTestLoader.loadTestsFromTestCase(DataConfigurationPage_TestCase.DataConfigurationPage_TestCase),            
            ])
        runner = unittest.TextTestRunner()
        runner.run (self.suite)

import unittest
if __name__ == "__main__":
    unittest.main()

在Jenkins中,我配置了以下内容:

从Build,Execute Windows Batch Command部分

copy E:\RL Fusion\projects\Jenkins sample\ClearCore501\TestCases\*.py
python smoketests.py

从Post-Build Actions部分,发布JUnit测试结果报告

test_reports/*..xml

在test_reports / * .. xml下面显示:

    ‘test_reports/*..xml’ doesn’t match anything: even ‘test_reports’ doesn’t exist

我如何让这个工作好吗?我究竟做错了什么? 有没有我可以遵循的示例演示,然后我可以让我的设置工作? 谢谢,

里亚兹

1 个答案:

答案 0 :(得分:0)

问题似乎出现在批处理文件的复制步骤中。请注意它是如何说它找不到文件的。使用双引号将源路径和目标路径包围,以便窗口知道您的路径中包含空格。

复制操作似乎也没有指定目的地。你应该也可能要指定它。虽然显然这不是一个要求,但我刚刚发现:)。

复制操作成功后,请检查工作区目录以查看您期望的文件是否存在。

或者,您可以告诉Jenkins作业使用自定义工作区,即测试所在的目录。使用此配置,您甚至不必担心复制文件。

以下是:

在Jenkins的作业配置中,打开 高级项目选项 ,然后选择 使用自定义工作区 并设置E:\RL Fusion\projects\Jenkins sample\ClearCore501\TestCases\的目录 然后构建命令可以是python smoketests.py