To Store / Extract and Use variables in between coded steps

2 posts, 1 answers
  1. Ravindra Naidu
    Ravindra Naidu avatar
    1 posts
    Member since:
    Aug 2014

    Posted 18 Apr 2016 Link to this post


    My scenario is - I have a value being generated on the fly (by appending the current time stamp) and could store it in a String in a Coded step. But, I'm unable to use/refer the variable in another coded step. Also, I require to verify an element having this variable's value as its identifier.

    Here, the "PriceName" is where I'm trying to generate a value and to make use of in another coded step and wanna use to identify an element. I tried using SetExtractedValue, GetExtractedValue, Utility.valueHolder...but, facing one or the other issue like "not stored in data source... , might be restricted due to its scope... , Null exception..."


    Value is generating and storing in "Public Sub Library_AddPrice_ValueRange_CodedStep()".

    Value to be accessed in "Public Sub Library_AddPrice_ValueRange_CodedStep1()"


    Below is the entire code for your easy reference...Please help.


    Imports Telerik.TestingFramework.Controls.KendoUI
    Imports Telerik.WebAii.Controls.Html
    Imports Telerik.WebAii.Controls.Xaml
    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

    Namespace Version7_21
    Public NotInheritable Class Utility
        Private Sub New()
        End Sub

        Public Shared valueHolder As String
        Public Shared Sub writeToFile(path As [String], content As [String])

            Dim file As New System.IO.StreamWriter(path)
        End Sub
    End Class

        Public Class Library_AddPrice_ValueRange
            Inherits BaseWebAiiTest

    #Region "[ Dynamic Pages Reference ]"

            Private _pages As Pages
            ''' Gets the Pages object that has references
            ''' to all the elements, frames or regions
            ''' in this project.
            Public ReadOnly Property Pages() As Pages
                    If (_pages Is Nothing) Then
                        _pages = New Pages(Manager.Current)
                    End If
                    Return _pages
                End Get
            End Property
    #End Region
            ' Add your test methods here...

            <CodedStep("Entering Price Label")> _
            Public Sub Library_AddPrice_ValueRange_CodedStep()
                Dim str1, str2
                Dim PriceName AS String
                str1 = System.DateTime.Now.ToString("HH:mm:ss").Replace("/","")
                str2 = str1.Replace(":","")
                PriceName = "Price Fee " + str2.Replace(" ","")
                SetExtractedValue("PriceName", PriceName)
                Dim FeeName As String = GetExtractedValue("PriceName")
                SetExtractedValue("PriceFeeName", FeeName)
                Dim myData As Object = GetExtractedValue("PriceFeeName")
                Utility.valueHolder = GetExtractedValue("PriceName")
                Utility.writeToFile("D:\OBFS Project\V 7.21\PDFS_Version7.21\Data\PriceDataSheet.xls", Utility.valueHolder)
                Manager.Desktop.KeyBoard.TypeText(PriceName, 50, 100, true)
            End Sub

            '<CodedStep("New Coded Step")> _
            'Public Sub Library_AddPrice_ValueRange_CodedStep1()
            'End Sub

        End Class
    End Namespace

  2. Answer
    Boyan Boev
    Boyan Boev avatar
    1072 posts

    Posted 21 Apr 2016 Link to this post

    Hi Ravindra,

    You don't need to use Utility.ValueHolder. After setting the extracted value in the first coded step you can directly print it into the log with:

    Log.WriteLine("I am comming fromt the second coded step: " + GetExtractedValue("PriceFeeName").ToString())

    Please find attached a project which demonstrates it.

    Let me know if that helps.

    Boyan Boev
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
Back to Top