Problem with C# code in test started from Jenkins

Ask general questions here.
User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3930
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Problem with C# code in test started from Jenkins

Post by odklizec » Tue May 28, 2013 9:14 am

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
FileExists.png (20.79 KiB) Viewed 1973 times
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!
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3930
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

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

Post by odklizec » Wed May 29, 2013 9:28 am

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? ;)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

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

Post by Support Team » Wed May 29, 2013 11:12 am

Hi,

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

Thanks,
Markus
.
Image

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3930
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

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

Post by odklizec » Wed May 29, 2013 12:05 pm

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 ;)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration