This is a migrated thread and some comments may be shown as answers.

Parameterize the handle 'FileUpload' dialog

4 Answers 160 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Nigel
Top achievements
Rank 2
Nigel asked on 13 Feb 2012, 02:27 PM
Hi,

I would like to know if it's possible to parameterize the Handle 'FileUpload' dialog.
What I have is a list of around 20 files in an Excel sheet.  The sheet contains other columns of data that I don't want to interact with.  The sheet is not bound as a data source as I don't want to iterate through all the rows.  I just need to select one row at random, abstract the file name & path from the appropriate column, and upload it.  What is the best way of doing this?  I've read the 'Random Row' guide in the on-line help, so I think I can select the random element, but I'm still uncertain how to apply it to this particular kind of test.

Thanks,
Nigel Edwards, Transition Computing.

4 Answers, 1 is accepted

Sort by
0
Anthony
Telerik team
answered on 13 Feb 2012, 04:51 PM
Hello Nigel,

Once you get your random value from the Excel file, set it as an extracted value in the same coded step. See the second code block here for an example.

Now you can use that variable to data bind the File Upload step, using the FileUploadPath property. See here for an example.

Kind regards,
Anthony
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Nigel
Top achievements
Rank 2
answered on 13 Feb 2012, 05:38 PM
Hi Anthony, and thanks for your promptness.  I'm still having problems and hope that you can see where I'm going wrong from the following.
Here is my test line in Test Studio:
    Handle 'FileUpload' dialog. - DataDriven: [$(fileToUse)]

(My settings include a project reference to Microsoft.Office.Interop.Excel, Version =14.0.0.0)
Now here's my code behind. First the Imports:

    Imports Telerik.WebAii.Controls.Html
    Imports Telerik.WebAii.Controls.Xaml
    Imports Telerik.WebAii.Controls.Xaml.Wpf
    Imports System
    Imports System.Collections.Generic
    Imports System.Text
    Imports System.Linq

    Imports ArtOfTest.Common.UnitTesting
    Imports ArtOfTest.WebAii.Core
    Imports ArtOfTest.WebAii.Controls.HtmlControls
    Imports ArtOfTest.WebAii.Controls.HtmlControls.HtmlAsserts
    Imports ArtOfTest.WebAii.Design
    Imports ArtOfTest.WebAii.Design.Execution
    Imports ArtOfTest.WebAii.ObjectModel
    Imports ArtOfTest.WebAii.Silverlight
    Imports ArtOfTest.WebAii.Silverlight.UI

    Imports Microsoft.Office.Interop

Now the Sub:
        <CodedStep("New Coded Step")> _
        Public Sub SelectRandomFile()
            Dim random As New Random()
            Dim num As Integer = random.[Next](1, 44)
            Dim input As String = "C:\Users\edwardni\Documents\Test Studio Projects\Base\Data\BaseData.xlsx"
            Dim app As New Microsoft.Office.Interop.Excel.Application()
            Dim inputBook As Microsoft.Office.Interop.Excel.Workbook = app.Workbooks.Open(input, 0, False, 5, "", "", False, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", True, False, 0, True, False, False)
            Dim inputSheet As Microsoft.Office.Interop.Excel.Worksheet = DirectCast((inputBook.Worksheets.Item("UI_Schemes")), Microsoft.Office.Interop.Excel.Worksheet)
'''The next three lines (tried one at a time, of course!) all produce the same error log result '''
            'Dim selection As String = TryCast(DirectCast(inputSheet.Cells(num, 3), Microsoft.Office.Interop.Excel.Range).Text, String)
            'Dim selection As Object = TryCast(DirectCast(inputSheet.Cells(num, 3), Microsoft.Office.Interop.Excel.Range).Text, String)
            Dim selection As Object = GetExtractedValue(TryCast(DirectCast(inputSheet.Cells(num, 3), Microsoft.Office.Interop.Excel.Range).Text, String))
            SetExtractedValue("fileToUse", selection)            
            app.Quit() 
            app = Nothing
        End Sub

What the log reports is:

'13/02/2012 16:23:00' - Using .Net Runtime version: '4.0.30319.235' for tests execution.'13/02/2012 16:23:00' - Starting execution....'13/02/2012 16:23:08' - Detected custom code in test. Locating test assembly: Base.dll.'13/02/2012 16:23:08' - Assembly Found: C:\Users\edwardni\Documents\Test Studio Projects\Base\bin\Base.dll'13/02/2012 16:23:08' - Loading code class: 'SetupRandomLogo'.'13/02/2012 16:23:08' - Failure detected during execution. Details:
------------------------------------------------------------
'13/02/2012 16:23:08' - System.NullReferenceException: Object reference not set to an instance of an object. at ArtOfTest.Common.Design.Data.DataResolver.GetMatchValue(Match match, DataRow data, Boolean throwError) at ArtOfTest.Common.Design.Data.DataResolver.GetMatchString(String expression, DataRow data, Boolean error) at ArtOfTest.Common.Design.Extensibility.Descriptors.AutomationDescriptor.BindData(String propertyName) at ArtOfTest.Common.Design.Extensibility.Descriptors.AutomationDescriptor.BindData[T](String propertyName) at ArtOfTest.WebAii.Design.IntrinsicTranslators.Descriptors.FileUploadDialogHandlerDescriptor.InitializeDialogs(Browser browser) at ArtOfTest.WebAii.Design.Execution.ExecutionContext.SetDialogMonitoring(AutomationStepList steps, TestType testType) at ArtOfTest.WebAii.Design.Execution.ExecutionContext.SetDialogMonitoring(Test test) at ArtOfTest.WebAii.Design.Execution.ExecutionContext.SetDialogMonitoring() at ArtOfTest.WebAii.Design.Execution.ExecutionEngine.InternalExecuteTestIteration(Object codeBehindInstance) at ArtOfTest.WebAii.Design.Execution.ExecutionEngine.InternalExecuteTest(Test test, TestResult initializationResult) at ArtOfTest.WebAii.Design.Execution.TestExecuteProxy.ExecuteTest(ExecuteTestCommand command)

I'm sure I'm missing something really obvious, but I can't spot it (excusable, since I'm not and never have been, a developer!)  I look forward to your reply.
Thanks,
Nigel Edwards, Transition Computing.

 

0
Anthony
Telerik team
answered on 13 Feb 2012, 10:11 PM
Hello Nigel,

That's an odd error indeed. I was not able to reproduce it using your code. I have a few more questions/suggestions to troubleshoot this:

  • Confirm that the coded step comes before the Upload Dialog Handler step.
  • Confirm the DataEnabled Test Property is checked. Although the test is not data driven, this is required for the Upload step to work properly with the extracted value.
  • Confirm the error occurs on the Handle Dialog step.

Also add some lines to your code to ensure the value is extracted from the correct row and column from the Excel sheet:

Dim selection As String = TryCast(DirectCast(inputSheet.Cells(num, 2), Microsoft.Office.Interop.Excel.Range).Text, String)
SetExtractedValue("fileToUse", selection)
 
'--Start new code
Dim d As Object = GetExtractedValue("fileToUse")
Log.WriteLine(d.ToString())
'--End new code
 
app.Quit()
app = Nothing

As a last resort, send us your test project so we can see the issue first-hand. If it exceeds the 20 MB limit, see here on what to exclude to bring down the file size. If you feel the info sensitive, attach it to a support ticket which is confidential, unlike this forum.

Regards,
Anthony
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Nigel
Top achievements
Rank 2
answered on 14 Feb 2012, 11:58 AM
Hi Anthony, and thanks for your persistence.
Your points:
  • Confirm that the coded step comes before the Upload Dialog Handler step.   YES, it does
  • Confirm the DataEnabled Test Property is checked. Although the test is not data driven, this is required for the Upload step to work properly with the extracted value.  YES, it is
  • Confirm the error occurs on the Handle Dialog step. 
  • Your last point doesn't actually apply.  I'll raise a ticket, as you suggest, to take this furhter, but thanks for your help to this point.  :)


    Tags
    General Discussions
    Asked by
    Nigel
    Top achievements
    Rank 2
    Answers by
    Anthony
    Telerik team
    Nigel
    Top achievements
    Rank 2
    Share this question
    or