다음을 통해 공유


Data driven Coded UI test with Dynamics AX

I recently had the need to explore using Visual Studio Coded UI capabilities to create some data in Dynamics AX. I had never used the data driven test capability in VS and was pleasantly surprised to see how easy it was to use. Having no experience with data driven tests, I created the following in less than a half hour. and could do it again in just a few minutes now that I know what I’m doing. Here’s what I did.

First, I created a new test project and a new coded UI test in VS. I selected “Use Coded UI Test Builder…” to record the steps to create a customer. The steps were quite straight forward for this prototype.

  1. Select New Customer from the All customers list page.
  2. Enter the Name, Customer group, and Country / region in the Customer – New record form as shown below
  3. Select Save and close.

After recording those steps, I selected Generate code and named the method CreateCustomer.

image

Now that I have a simple test that will create a single customer, I need to add the data driven aspect of the prototype. For this I relied on MSDN (https://msdn.microsoft.com/en-us/library/ee624082.aspx) and Mathew Aniyan’s blog post (https://blogs.msdn.com/b/mathew_aniyan/archive/2009/03/17/data-driving-coded-ui-tests.aspx). This is where the pleasant surprise came as this was very straight forward.

I created an Excel spreadsheet with three columns – CustName, CustGroup, and Region. I added 10 rows of data to the spreadsheet and saved it as a CSV file.

image

Following the documentation, I set the Data Connection String attribute to the location of the CSV file using the wizard that came up from the lookup button on the field. The path to this property is described in the MSDN article referenced above. The result of this was a new attribute code generated for my test method.

The last step was to map the columns of the spreadsheet to the internal variables used for the fields that I wanted to set. IntelliSense guided my way, resulting in the test method shown below:

[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\CustomerInputs.csv", "CustomerInputs#csv", DataAccessMethod.Sequential), DeploymentItem("DataDrivenCodedUIExample\\CustomerInputs.csv"), TestMethod]

public void CodedUITestMethod1()
{
     this.UIMap.CreateCustomerParams.UINameEditText = TestContext.DataRow["CustName"].ToString();
this.UIMap.CreateCustomerParams.UICustomergroupEditText = TestContext.DataRow["CustGroup"].ToString();
this.UIMap.CreateCustomerParams.UICountryregionEditText = TestContext.DataRow["Region"].ToString();
this.UIMap.CreateCustomer();

}

Running this test walks through the CreateCustomer steps for each row in the spreadsheet, creating 10 new customers in this case. Now I simply need to modify my spreadsheet to create variations of this data creation exercise! More typically, the data driven test capability would be used to drive a test case with a variety of inputs to get broader coverage of your application under test.