简体   繁体   English

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

[英]Selenium Python Configure Jenkins to run build. My build fails

I am trying to configure Jenkins to build my Selenium Webdriver Python code. 我正在尝试配置Jenkins以构建我的Selenium Webdriver Python代码。 When i click Build Now it fails The Console output shows the following: 当我单击“立即构建”时,它将失败。控制台输出显示以下内容:

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

In PyCharm i have a smoketests.py file as follows: 在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)

I have a test_HTMLRunner.py as follows: 我有一个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)

I have a suite.py as follows: 我有一个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()

In Jenkins I have configured the following: 在Jenkins中,我配置了以下内容:

From the section Build, Execute Windows Batch Command 在“构建,执行Windows批处理命令”部分中

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

From the section Post-Build Actions, Publish JUnit test result report 在“构建后操作”部分中,发布JUnit测试结果报告

test_reports/*..xml

Below test_reports/*..xml it shows: 在test_reports / * .. xml下面显示:

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

How do i get this to work please? 我该如何工作? What am i doing wrong? 我究竟做错了什么? Is there any sample demo I could follow and then I can get my setup to work? 有没有我可以遵循的示例演示,然后可以进行设置? Thanks, 谢谢,

Riaz 里亚兹

The problem looks to be in the copy step of you batch file. 问题似乎出在您批处理文件的复制步骤中。 Notice how it says it cant find the file. 请注意,它说它找不到文件。 Surround the source and destination paths with double quotes so that windows knows your path has spaces in it. 用双引号括住源路径和目标路径,以便Windows知道您的路径中有空格。

It also appears the copy operation doesn't have a destination specified. 似乎复制操作没有指定目的地。 You should may want to specify that too. 应该 可能要指定这一点。 Although apparently that isn't a requirement, as I just found out :). 虽然显然这不是必须的,但正如我刚刚发现的:)。

Once the copy operation succeeds, check the workspace directory to see if the file(s) you expect are present. 复制操作成功后,请检查工作区目录以查看是否存在您期望的文件。

Alternatively, you can tell the Jenkins job to use a custom workspace, the directory where your tests live. 或者,您可以告诉Jenkins作业使用自定义工作区,即测试所在的目录。 With this configuration you don't even have to worry about copying files. 使用此配置,您甚至不必担心复制文件。

Here's how: 这是如何做:

In the job config in Jenkins, open the Advanced Project Options and select use custom workspace and set the directory to E:\\RL Fusion\\projects\\Jenkins sample\\ClearCore501\\TestCases\\ . 在Jenkins的作业配置中,打开“ 高级项目选项”,然后选择“ 使用自定义工作区” ,并将目录设置为E:\\RL Fusion\\projects\\Jenkins sample\\ClearCore501\\TestCases\\
Then the build command can just be python smoketests.py . 然后,构建命令可以只是python smoketests.py

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

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