Page 1 of 1

Problem with C# code in test started from Jenkins

Posted: Tue May 28, 2013 9:14 am
by odklizec
Hi folks,

I'm experiencing a weird problem with a test started from Jenkins. My Jenkins configuration uses slave machines for building apps under different systems. Jenkins build is smooth and the Ranorex test is started and most of the test works OK. It just fails on one particular code I'm using in my test.

I'm using this code, to check the existence of a file, before using it in the next test step (loading the file via Open File dialog)...
public void Test_File_Exists(string FilePath)
        {
        	if (! System.IO.File.Exists(@FilePath))
        	{
        		// skip the iteration in case of missing file
        		throw new RanorexException("File Does not exist!"); 
        	}
        	else
        		Report.Log(ReportLevel.Success, "Validation", "File " + FilePath + " exists.");
        }
FileExists.png
The code works OK if I run the test project from Rx Studio or a windows command line (even on the Jenkins slave machine). From some mad reasons, exactly the same command line started from Jenkins runs the test, but the above code fails.

Here is a part of Rx log as seen in Jenkins (and Rx log file)...
[2013/05/28 09:30:30.715][Info ][Test]: Test Case Iteration #10' started.
[2013/05/28 09:30:30.715][Info ][Test]: Test Module 'Load_File_From_CSV' started.
[2013/05/28 09:30:30.871][Info ][Data]: Current variable values:
$SetJTFilePath = '\\krivan\projectmng\test_scenarios\jtmodels\_AFCC7101412.jt', $AUTProcessName = 'java'
[2013/05/28 09:30:30.996][Info ][Mouse]: Mouse Left Click item 'LiteBox3d.FileOpenBtn' at 17;7.
[2013/05/28 09:30:31.449][Error ][Module]: File Does not exist!
[2013/05/28 09:30:31.840][Failure][Test]: Test Module 'Load_File_From_CSV' completed with status 'Failed'.
[2013/05/28 09:30:31.840][Failure][Test]: Test Case Iteration #10 completed with status 'Failed'.
As I said, the code works OK if the test is started from the Rx studio of manually from the command line. I tried both release and debug version of test. Any idea what to try or where to look? And yes, the files definitely exist ;)

Thank you in advance!

Re: Problem with C# code in test started from Jenkins

Posted: Wed May 29, 2013 9:28 am
by odklizec
OK, I found the cause of my problem. The problem is caused by the fact that the Jenkins slave service (all win services) is run from the system user account, which has not stored credentials to access the network paths. Unfortunately, there seems to be not an easy way to overcome this issue.

The easiest way to access the network paths from Jenkins slave is to map the network path to a drive. Sadly, it's easier to say than do. It's really tricky to do so on a system account level.

The workaround requires to create a new windows service, run the cmd.exe from that service, map the network path from that cmd.exe and finally, delete the service. Here is the command line I run after each VM restart (the mapped drive is lost after restart).
cmd /c sc create testsvc binPath= "cmd /c net use k: /delete & net use z: \"\\server\directory\" /user:domain\username password" type= own type= interact & net start testsvc & sc delete testsvc
It's a good idea to create a batch file and put it to the startup folder.

If you are interested, you can find more details about the above used technique here:
http://forum.sysinternals.com/tip-run-p ... 16714.html

Hope it helps someone else? ;)

Re: Problem with C# code in test started from Jenkins

Posted: Wed May 29, 2013 11:12 am
by Support Team
Hi,

Therefore it is not recommended to use network drives ;), but thanks for posting your solution :)!

Thanks,
Markus

Re: Problem with C# code in test started from Jenkins

Posted: Wed May 29, 2013 12:05 pm
by odklizec
Well, yes, I too don't like to use network drives. But it's cleaner solution and easier to manage one public source of test files, than multiple local copies. On the other hand, it may be sensible to manage the test files via a source control system? Something to think about ;)