Hi,
I have gone through the posts in this forum which states how to set relative path of excel file in the 'Manage Data Sources' part by checking the 'Copy file to project' checkbox. I have done the same in my testcase. Now I want to set the relative path of the same excel file in my usercode as I need to write some values in my excel sheet from web application. Please follow the code which am using for writing in excel file:
var excelApp = new Excel.Application();
excelApp.Visible = true;
excelApp.Workbooks.Open("C:/Work/Automation/TowCall_D3.xlsx");
Excel._Worksheet worksheet = (Excel.Worksheet)excelApp.ActiveSheet;
worksheet.Cells[2,"AS"] = strcallID;
excelApp.ActiveWorkbook.Save();
excelApp.Quit();
For the line where am setting the excel file path I want to use a relative path just like it happens in 'Manage Data Sources' part by checking the 'Copy file to project' checkbox.
Note: I want to use a relative path because the scripts would be run in different machines and hence users need to create a folder in their local machine (C:/Work/Automation/TowCall_D3.xlsx). Also replace the excel everytime it is updated by 1 user.
Please let me know the solution for this. Thanks in advance.
How to set relative path of excel file in Usercode.cs?
-
- Posts: 8
- Joined: Mon Dec 19, 2016 8:53 am
How to set relative path of excel file in Usercode.cs?
You do not have the required permissions to view the files attached to this post.
-
- Posts: 8
- Joined: Mon Dec 19, 2016 8:53 am
Re: How to set relative path of excel file in Usercode.cs?
Please let me know if there is any solution to my above stated problem. Looking forward to your reply.
Thanks in advance.
Thanks in advance.
Re: How to set relative path of excel file in Usercode.cs?
Hi,
A relative path to what...the test exe? In this case, you can use something like this:Hope this helps?
BTW, users should not be needed to create anything manually! I would strongly suggest to use a proper version control system, to distribute your tests (ideally combined with continuous integration system, like Jenkins, Bamboo, etc...). Copying files manually is a certain way to mess and confusion
A relative path to what...the test exe? In this case, you can use something like this:
Code: Select all
string getActualDir = TestSuite.WorkingDirectory.ToString();
excelApp.Workbooks.Open(getActualDir + "\\TowCall_D3.xlsx");
...
BTW, users should not be needed to create anything manually! I would strongly suggest to use a proper version control system, to distribute your tests (ideally combined with continuous integration system, like Jenkins, Bamboo, etc...). Copying files manually is a certain way to mess and confusion
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
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