This is a migrated thread and some comments may be shown as answers.

Step to delete a file

5 Answers 103 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Graeme
Top achievements
Rank 1
Graeme asked on 10 Dec 2015, 12:06 PM

I'm trying to make Test Studio verify that if a WPF app has no licence, it prompts for one when it is started. I've got that working, but I want to add a step that deletes a licence file from disk before the app is launched.

What is the best way to add a step that will delete a file from disk? Is there a better way of doing this? (I'm new to Test Studio, and Automation in general)

5 Answers, 1 is accepted

Sort by
0
Boyan Boev
Telerik team
answered on 10 Dec 2015, 12:33 PM
Hi Graeme,

Thank you for contacting us.

This can be achieved in a coded step. You should write a code which verify whether the file exists and then delete it.

Here is a simple example of this.

Let me know if that helps.

Regards,
Boyan Boev
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Graeme
Top achievements
Rank 1
answered on 10 Dec 2015, 02:26 PM

Thanks. I now have a coded step that looks something like:

string commonAppData = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
 string licFile = System.IO.Path.Combine(commonAppData, @"Vendor\Product\Licence\Product.lic");
 
 if (System.IO.File.Exists(licFile)) {
    System.IO.File.Delete(licFile);
}

, but I really want this file to be gone before my WPF app is loaded. How should I go executing about steps before loading the app?
0
Boyan Boev
Telerik team
answered on 11 Dec 2015, 09:06 AM
Hi Graeme,

In this case you should implement the same code in OnBeforeTestStarted method in our execution extension.

This method triggers just before the test is started.

Hope that helps.

Regards,
Boyan Boev
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Graeme
Top achievements
Rank 1
answered on 15 Dec 2015, 12:35 PM
Is there no way to do this without developing a dll in visual studio?
0
Boyan Boev
Telerik team
answered on 15 Dec 2015, 02:05 PM
Hi Graeme,

Unfortunately there is no other way. 

If you want to execute this code before the start of the test this is the only way how to achieve it.

Thank you for your understanding.

Regards,
Boyan Boev
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Graeme
Top achievements
Rank 1
Answers by
Boyan Boev
Telerik team
Graeme
Top achievements
Rank 1
Share this question
or