Where should I keep an mp4 file(test data) in specflow framework and how do I get its path?

13 views
Skip to first unread message

sundresh

unread,
Mar 19, 2020, 6:00:36 PM3/19/20
to SpecRun
HI Community,

I am struggling with this:

I need to test if upload file feature works and need to fetch the .mp4 file in test case.
I tried keeping it in test data folder inside project and getting project directory using Directory.GetCurrentDirectory(); but that gives the TestResults Folder. 

Any recommendations would help

Advance Thanks and Stay Safe!

xDazedx

unread,
Mar 19, 2020, 10:47:21 PM3/19/20
to spe...@googlegroups.com
Create a folder in your solution and add the files. 

add the below GetBasePath method. There are a variety of ways you can do this. 

ex: Create a folder called "Files" and add "test.mp4" to it in your solution. 

Step:
And I can upload image test.mp4

Feature: 

        [When(@"I can upload image (.*) ")]
        public void WhenICanUploadImage(string value)
        {

            var path = GetBasePath;
            string filePath = string.Format(path + @"\Files\{0}", value);
            FindElement_byXPath("//div[@class='myClass']//input[@class='input']").SendKeys(filePath);

        }

GetBasePath function is great because if you run local on D: and Jenkins is running on E: drive, no changes are required.  Debug the above and then adjust the path from there depending on where you added the Files folder.  


        public static string GetBasePath
       
{
           
get
           
{
               
var basePath =
                   
System.IO.Path.GetDirectoryName((System.Reflection.Assembly.GetExecutingAssembly().Location));
                basePath
= basePath.Substring(0, basePath.Length - 10);
               
return basePath;
           
}
       
}


Reply all
Reply to author
Forward
0 new messages