This project has moved. For the latest updates, please go here.

Support for Fields

May 18, 2012 at 9:43 PM

Good afternoon,

I am interested in accessing the fields property in a document, so that I can assert the value of the Field.Code property in the case of fields in a Word document.  

I tried to add this functionality myself; I added the following line in the GetSelectionProperty in UITestCommunicator.cs (WordAddIn project)

 

case PropertyNames.Fields: return selection.Fields;

 

However, when I tried to access that property using UITestControl's GetProperty method, I got the following error:

Test method CuiAutoTagTagTestProject.CuiAutoTagTagTests.InsertOutTag threw exception: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dllRunning under executable  C:\Program Files\Microsoft Office\Office14\WINWORD.EXE--- A detailed error log follows. 
=== Pre-bind state information ===LOG: User = WINDWARD\marcusjLOG: DisplayName = Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a (Fully-specified)LOG: Appbase = file:///C:/Users/marcusj/AppData/Roaming/Microsoft Visual Studio ALM Rangers/Coded UI Word 2010 Add-in/LOG: Initial PrivatePath = NULLCalling assembly : (Unknown).===LOG: This bind starts in default load context.LOG: No application configuration file found.LOG: Using host configuration file: LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.LOG: Post-policy reference: Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3aLOG: Attempting download of new URL file:///C:/Users/marcusj/AppData/Roaming/Microsoft Visual Studio ALM Rangers/Coded UI Word 2010 Add-in/Microsoft.VisualStudio.TestTools.UITest.Extension.DLL.LOG: Attempting download of new URL file:///C:/Users/marcusj/AppData/Roaming/Microsoft Visual Studio ALM Rangers/Coded UI Word 2010 Add-in/Microsoft.VisualStudio.TestTools.UITest.Extension/Microsoft.VisualStudio.TestTools.UITest.Extension.DLL.LOG: Attempting download of new URL file:///C:/Users/marcusj/AppData/Roaming/Microsoft Visual Studio ALM Rangers/Coded UI Word 2010 Add-in/Microsoft.VisualStudio.TestTools.UITest.Extension.EXE.LOG: Attempting download of new URL file:///C:/Users/marcusj/AppData/Roaming/Microsoft Visual Studio ALM Rangers/Coded UI Word 2010 Add-in/Microsoft.VisualStudio.TestTools.UITest.Extension/Microsoft.VisualStudio.TestTools.UITest.Extension.EXE.

 

I also tried modifying it slightly so it would only return me selection.Fields[0].Code.Text, however I then received a COMException saying the requested member of the collection does not exist.

May 24, 2012 at 3:35 PM
Edited May 24, 2012 at 3:39 PM

Well, I also included a line in WordPropertyProvider (WordExtension/WordPropertyProvider.cs) in the InitializePropertiesMap method:

map.Add(PropertyNames.Fields, new UITestPropertyDescriptor(typeof(Word.Fields), Read));

But I still had the same error.

I more or less figured this out.  I'm not sure why, but the file: file:///C:/Users/marcusj/AppData/Roaming/Microsoft Visual Studio ALM Rangers/Coded UI Word 2010 Add-in/Microsoft.VisualStudio.TestTools.UITest.Extension.DLL didn't exist.  

A quick search of the C: drive and I found the file in C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies.  Copied it over and everything has worked.

As far as the second problem I was having when trying to access selection.Fields[0].Code.Text, it turns out Word starts Fields off at 1, so the first field was at Fields[1].

Developer
May 30, 2012 at 8:50 PM

Hi

I've just wrapped up the RC but I think you have a very valid request. I'll see if we can get this functionality built into the Add-In for RTM

Thanks for the feedback!

Developer
May 30, 2012 at 9:28 PM

FYI: I've added a work item here to track this http://vsarcodeduiword.codeplex.com/workitem/18159. Will also add to our internal system.