How to remove readonly mode from .cs file after recording

Ranorex Spy, Recorder, and Studio.
smohanty78
Posts: 23
Joined: Tue Feb 10, 2015 10:51 am

How to remove readonly mode from .cs file after recording

Post by smohanty78 » Tue Feb 10, 2015 11:06 am

Hi
After recording I would like to do some changes directly to .cs file.
Could you please tell me how to write to the file? as it comes as read-only file
Regards,
Sangita

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: How to remove readonly mode from .cs file after recording

Post by krstcs » Tue Feb 10, 2015 2:55 pm

***Do NOT change the .cs files that are locked.***

They are locked because they are generated by Ranorex and should not be manipulated as it could cause problems.

Also, any changes made to the file will be destroyed when the file is re-written by Ranorex.




If you need to write code-behind for a Recording module, you should use the *.UserCode.cs file. Add a UserCode action to the action table and then add a method to the UserCode file.
Shortcuts usually aren't...

andrefelipe
Posts: 13
Joined: Tue Feb 03, 2015 6:00 pm

Re: How to remove readonly mode from .cs file after recording

Post by andrefelipe » Tue Feb 10, 2015 2:57 pm

Hello smohanty78,

As far as I know, Recorded modules, are generated by Ranorex and they cannot be changed.
But they are all partial class, with a UserCode part, where you can add your own methods and call them in the recording module.

Here we go:

Find the usercode part
Image

Open and add what you want
Image

Add a usercode activity, and call your method.
Image

The other option, is to write an entire usercode module, but I don't think that's what you want.

Regards,
André Felipe
Attachments
ForumHelp.zip
Code Example
(10.47 KiB) Downloaded 102 times

smohanty78
Posts: 23
Joined: Tue Feb 10, 2015 10:51 am

Re: How to remove readonly mode from .cs file after recording

Post by smohanty78 » Tue Mar 31, 2015 1:29 pm

Thanks a lot for the nice explanation.

conradb
Posts: 19
Joined: Thu Mar 10, 2016 12:00 pm

Re: How to remove readonly mode from .cs file after recording

Post by conradb » Wed Apr 27, 2016 12:16 pm

I just randomly found myself in the same situation:
I added two actions to a recording, and the disabled a different action, but every time I ran the test it was clearly running the old/origional test code. I restarted Ranorex and rebuilt the solution 3 times, problem persisted. I then saw that Ranorex "thinks" the generated C# file is read-only, and the file was not re-generating.
1. I worked around it by just deleting the generated file.
2. Why did the build task not error? I assume the generated file .cs is not a dependency of the recording .rxrec - or the computer time was out and thus the recording was not newer according to the make rules?

I am using perforce version control, which apparently is not compatible, and we are checking generated files into the version control, and then checking all files out whenever we do any work.

Next time I'll just delete the generated file as a first thing to try :-)
pros:Powershell automation guru
cons:UI automation hacker/n00b
Conrad Braam

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

Re: How to remove readonly mode from .cs file after recording

Post by odklizec » Wed Apr 27, 2016 12:29 pm

Hi,

I don't know Perforce version control system, but I guess the read-only is caused by Perforce itself? I remember a similar issue caused by TFS, where server-based workspace caused read-only flag to local files. Once the workspace has been switched to 'local', the read-only problem was fixed. So I would suggest to search/discuss this behavior with Perforce support?
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

conradb
Posts: 19
Joined: Thu Mar 10, 2016 12:00 pm

Re: How to remove readonly mode from .cs file after recording

Post by conradb » Wed Apr 27, 2016 2:30 pm

It's my "future" intention to delete all generated files and somehow get our build script to regenerate them in future via msbuild. This would fit with the pattern of not ever storing any files that one can easily generate.

I'm pretty sure it was finger problems on my part that got me here, since I have a script that makes all files read-write after I sync down the code. Thanks once again for the quick responses.
pros:Powershell automation guru
cons:UI automation hacker/n00b
Conrad Braam

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: How to remove readonly mode from .cs file after recording

Post by krstcs » Wed Apr 27, 2016 2:33 pm

Yeah, I agree with Pavel. Sounds like your version control system set the file to read-only.

Ranorex doesn't mark the .cs file read-only in the file-system, only in Ranorex Studio. You can make manual changes to those files all day long in another text editor and Ranorex won't care, you just can't do it through Studio itself.
Shortcuts usually aren't...

conradb
Posts: 19
Joined: Thu Mar 10, 2016 12:00 pm

Re: How to remove readonly mode from .cs file after recording

Post by conradb » Fri Apr 29, 2016 2:37 pm

When I delete all the generated files (files that contained the warning banner ) and then click "clean", then click "build solution" in studio it creates a swathe of warnings for each missing file.

Is deleting all files containing 'DO NOT MODIFY THIS FILE!' the correct strategy for force a project to upgrade to a newer version of studio?
pros:Powershell automation guru
cons:UI automation hacker/n00b
Conrad Braam

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: How to remove readonly mode from .cs file after recording

Post by krstcs » Fri Apr 29, 2016 3:25 pm

No, Ranorex automatically updates the .cs files every time you build the projects or solution. You should not delete the files as Ranorex only generates the file when the module is first created, it just regenerates the contents when you change the rxrec file or when you recompile.
Shortcuts usually aren't...

conradb
Posts: 19
Joined: Thu Mar 10, 2016 12:00 pm

Re: How to remove readonly mode from .cs file after recording

Post by conradb » Tue May 03, 2016 12:30 pm

My intention with deleting all generated or generateable files was to be able to remove them from version control, and then to get them to regenerate in the MSBuild script. I hoped it slightly reduces number of files to check in when doing an average test change, but most fixes seem to touch quite a few files, so eliminating generated files is not a massive win.

So yes, you can delete them, but it's not really useful to do so in the end.
pros:Powershell automation guru
cons:UI automation hacker/n00b
Conrad Braam