Coded UI driving test from multiple excel files

泄露秘密 提交于 2019-12-11 00:28:04

问题


Our strategy for using Coded UI to test our software is to create several Excel spreadsheets each with the testing steps for a particular test case. There will be one Driver spreadsheet that has a worksheet that lists the test cases to be run. The idea is to read the Driver spreadsheet and then go open the individual test case spreadsheets to run the test steps. The test steps will list a button or field, the action to perform (click, edit) and the data value or other expected result which will be passed to helper functions in the UIMap or hand written map.

In my Coded UI project I have only one test method and it has one spreadsheet data binding associated with it. I can open that file and read it with no problems. How do I close that spreadsheet file and go open a different one at run time?

What other ways are there to do what I am trying to do?


回答1:


Use

using Microsoft.Office.Interop.Excel;

To open an instance of Excel:

private Microsoft.Office.Interop.Excel.Application excel;
...
excel = new Microsoft.Office.Interop.Excel.Application();

To open a specific workbook:

private Workbook workbook;
....
workbook = excel.Workbooks.Open(@"\\C\Data\YourDriver.xlsx");

To get a specific worksheet:

Worksheet worksheet = workbook.Worksheets["YourTestCaseWorkSheet"];

To Kill your task:

    /// <summary>
    /// Quits the excel process
    /// </summary>
    public void Quit() 
    {
        Marshal.ReleaseComObject(this.worksheet);
        Marshal.ReleaseComObject(this.workbook);
        this.excel.Quit();
        this.excel = null;
    }

Put the Opening on the Excel sheet in the [TestInitialize] method and the Quit method in the [TestCleanup]. You should try - catch all test cases though with the Quit method to insure your excel processes close.

Note that test methods cannot run other test methods. So you'll be required to use one test case to run your multiple Excel test cases.

You can also build a batch file to run your tests through MSTEST.EXE.



来源:https://stackoverflow.com/questions/24048968/coded-ui-driving-test-from-multiple-excel-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!