Step to delete a file

6 posts, 0 answers
  1. Graeme
    Graeme avatar
    31 posts
    Member since:
    Aug 2014

    Posted 10 Dec 2015 Link to this post

    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)

  2. Boyan Boev
    Admin
    Boyan Boev avatar
    1045 posts

    Posted 10 Dec 2015 Link to this post

    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!
  3. Graeme
    Graeme avatar
    31 posts
    Member since:
    Aug 2014

    Posted 10 Dec 2015 in reply to Boyan Boev Link to this post

    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?
  4. Boyan Boev
    Admin
    Boyan Boev avatar
    1045 posts

    Posted 11 Dec 2015 Link to this post

    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!
  5. Graeme
    Graeme avatar
    31 posts
    Member since:
    Aug 2014

    Posted 15 Dec 2015 in reply to Boyan Boev Link to this post

    Is there no way to do this without developing a dll in visual studio?
  6. Boyan Boev
    Admin
    Boyan Boev avatar
    1045 posts

    Posted 15 Dec 2015 Link to this post

    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!
Back to Top