Question

Firoj Awate on Fri, 25 Jul 2014 08:38:23


Hi Team,

  I am getting below error while running coded ui test. This very irritating now. Want to get rid of this.

Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
System.FormatException
at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)
at System.String.Format(IFormatProvider provider, String format, Object[] args)
at Microsoft.VisualStudio.TestTools.UITest.Extension.EqtTrace.Warning(String format, Object[] args)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControlSearchArgument.get_TopLevelSearchArgument()
at Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.GetElement(Boolean useCache, ISearchArgument searchArg)
at Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.Search(ISearchArgument searchArg)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindInternal()
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindControlIfNecessary()
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.WaitForControlReadyPrivate(Int32 millisecondsTimeout, Boolean doLogging)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl+<>c__DisplayClass4a.<WaitForControlReady>b__49()
at Microsoft.VisualStudio.TestTools.UITesting.CodedUITestMethodInvoker.InvokeMethod(Func`1 function, UITestControl control, Boolean firePlaybackErrorEvent, Boolean logAsAction)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.WaitForControlReady(Int32 millisecondsTimeout)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.WaitForControlReady()
at RedThreadTest.UIMap.OpenClinicalChemistry()
in c:\C#\RedThreadTest\RedThreadTest\UIMap.cs:line 233
at RedThreadTest.KKLabRequest.CreateRequsition()
in c:\C#\RedThreadTest\RedThreadTest\KKLabRequest.cs:line 37


Regards, Firoj Awate

Replies

dwate88 on Fri, 25 Jul 2014 09:30:39


Hi Firoj,

Would you be able to provide the code which gives this error?

This is usually caused by a mismatch between the arguments provided for a string.Format call and the argument placeholders in the string

e.g. this will fail:

string.Format("The first value is {1}, the second value is {3}", stringValueVariable) 

This has a few problems:

1. The argument list has a zero-based index, so the first item should be {0}, not {1}.

2. item {2} has been skipped and jumped straight to {3}

3. only one argument value is given (i.e. stringValueVariable) whereas two arguments placeholders are specified.

This, on the other hand would work:

string.Format("The first value is {0}, the second value is {1}", value1, value2);

Hope this helps,

Firoj Awate on Fri, 25 Jul 2014 09:33:05


public void OpenClinicalChemistry()
        {
            #region Variable Declarations
            HtmlInputButton uIOrderButton = this.UIInternetExplorerWindow.UIOFSimulationDocument.UIOrderButton;
            HtmlCell uIAutomationCell = this.UIInternetExplorerWindow.UILabCentreMainDocument.UIAutomationCell;
            HtmlCell uIClinicalchemistryCell = this.UIInternetExplorerWindow.UILabCentreMainDocument.UIClinicalChemistryCell;
            #endregion
            Playback.PlaybackSettings.SearchTimeout = 90000;
            Playback.PlaybackSettings.MaximumRetryCount = 3;
            Playback.PlaybackError += Playback_PlaybackError;

           // Click 'Order' button
            Mouse.Click(uIOrderButton);

            // Click 'Automation' cell
            uIAutomationCell.WaitForControlReady();
            Mouse.Click(uIAutomationCell);

            // Click 'Clinical Chemistry' cell
            uIClinicalchemistryCell.WaitForControlReady();
            Mouse.Click(uIClinicalchemistryCell);
        }

           

Firoj Awate on Fri, 25 Jul 2014 09:37:47


Error Line is

 uIClinicalchemistryCell.WaitForControlReady();

dwate88 on Fri, 25 Jul 2014 10:09:15


Hi,

Well that is surprising.

Just out of interest, try adding an integer value to the WaitForControlReady() method, e.g.

 uIClinicalchemistryCell.WaitForControlReady(10000);

This shouldn't be needed (as it isn't needed in the implementation above this) but if it works it may give an idea of where to look for the problem.

Good luck,

Firoj Awate on Fri, 25 Jul 2014 10:17:24


Tried above workaround. Still same error. :(

dwate88 on Fri, 25 Jul 2014 10:21:25


Could you copy the line of code at UIMap.cs:line 233

I am clutching at straws now but might help.

Firoj Awate on Fri, 25 Jul 2014 10:23:20


c:\C#\RedThreadTest\RedThreadTest\UIMap.cs:line 233:


 uIClinicalchemistryCell.WaitForControlReady();

Second last line in the function I have written.

dwate88 on Fri, 25 Jul 2014 10:27:58


Sorry, of course, you were already showing your UIMap.

Can you go the definition of  this.UIInternetExplorerWindow.UILabCentreMainDocument.UIClinicalChemistryCell

in your UIMap.Designer.cs and copy all of that code?

Firoj Awate on Fri, 25 Jul 2014 10:30:09


public HtmlCell UIClinicalChemistryCell
        {
            get
            {
                if ((this.mUIClinicalChemistryCell == null))
                {
                    this.mUIClinicalChemistryCell = new HtmlCell(this);
                    #region Search Criteria
                    this.mUIClinicalChemistryCell.SearchProperties[HtmlCell.PropertyNames.Id] = "ClinicalAreaTab";
                    this.mUIClinicalChemistryCell.SearchProperties[HtmlCell.PropertyNames.Class] = "PassiveTabBtn";
                    this.mUIClinicalChemistryCell.SearchProperties[HtmlCell.PropertyNames.InnerText] = "Clinical Chemistry";
                    this.mUIClinicalChemistryCell.SearchProperties[HtmlCell.PropertyNames.ClassName] = "HtmlTableCell";
                    this.mUIClinicalChemistryCell.WindowTitles.Add("LabCentreMain");
                    #endregion
                }
                return this.mUIClinicalChemistryCell;
            }
        }

dwate88 on Fri, 25 Jul 2014 11:06:53


Hi Firoj,

I am stumped by this one, very odd.

I can't imagine that the code in the UIMap.Designer.cs would have any issues as it was recorded

Is there a definition of a row anywhere which contains this cell? Can you copy the code over if so?

If all else fails, might be worth putting this on the C# forum where more developers will see the thread.

Krishna Kumar Shukla on Fri, 25 Jul 2014 11:32:14


Hi Firoj,

I can not understand your question, can you define it more some screen shots ctc..,

Thanks

AdrianHHH on Fri, 25 Jul 2014 11:48:16


I think these two lines of the stack trace are significant perhaps get_TopLevelSearchArgument is passing a bad string.

at Microsoft.VisualStudio.TestTools.UITest.Extension.EqtTrace.Warning(String format, Object[] args)

at Microsoft.VisualStudio.TestTools.UITesting.UITestControlSearchArgument.get_TopLevelSearchArgument()

Does your test data include curly braces anywhere?

You could run your test with the Visual Studio debugger. It may stop on the exception, depending on exactly how the debugger is configured, alternatively it may be easy to put a breakpoint on the uIClinicalchemistryCell.WaitForControlReady(); line and step into the methods until near the failure point. In either case look at the arguments to method calls looking for arrays and indexes into arrays. Also look at all the strings for a "{" followed by a number.

Regards

Adrian

Firoj Awate on Fri, 25 Jul 2014 11:53:48


The code works fine with Visual Studio Debugger.  When I deploy it to environment it fails with Exception.

There are not "{" braces used anywhere.

AdrianHHH on Fri, 25 Jul 2014 13:03:21


So the problem is with the environment. Can you run the test under the debugger on the machine where the test failed? Can you compare the software versions installed on the development and the execution machine? I do not recognise the routines in these two lines, so I would check their (or their files) versions first.

at Microsoft.VisualStudio.TestTools.UITest.Extension.EqtTrace.Warning(String format, Object[] args)

at Microsoft.VisualStudio.TestTools.UITesting.UITestControlSearchArgument.get_TopLevelSearchArgument()

Debugging can be hard work. You know the test runs on one computer and not on another so you can be confident that there is something different between them. You just need to find that difference.

Regards

Adrian

Amanda Zhu on Mon, 28 Jul 2014 05:42:55


Hi Firoj,

Adrain’s doubts and suggestions are very useful, please try it and tell use the result.

Another doubt from me is that whether your application changed after you deploy the application to another machine for example a row/cell’s index.

If possible, you can install a Visual Studio on the test agent machine, run the same test or do a new test against this deployed application to check the result.

Thanks,

Amanda Zhu on Thu, 31 Jul 2014 01:28:47


Any update? Whether the issue was resolved?

Firoj Awate on Thu, 31 Jul 2014 04:43:31


Unfortunately test environment is down from last week so unable to do the activities.

I will update soon with details.