Selenium Python Configure Jenkins to run build. My build fails
Question: I am trying to configure Jenkins to build my Selenium Webdriver Python code.
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:

    
    
        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:

    
    
    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:

    
    
        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:

From the section Build, Execute Windows Batch Command

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

From the section Post-Build Actions, Publish JUnit test result report

    
    
    test_reports/*..xml
    

Below test_reports/*..xml it shows:

    
    
        ‘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


Answer: 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.

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. 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\`.  
Then the build command can just be `python smoketests.py`.

