Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE
TrntGty1 Absent Member.
Absent Member.
1992 views

Why is it so hard to capture timings and write them out line by line into a notepad file in a .NET script? Seems so simple but I cannot find an answer.

Jump to solution

I have a spreadsheet.

This spreadsheet contains the values that get input into our formulas on the website.

Spreadsheet contains expected values.

Website contains actual values.

I want Silk Test to input the values from a spreadsheet, capture the output from the website, and then write it to a notepad comma delimited file line by line with each line representing each step.

ActiveData can pull from a spreadsheet.  Do I need to setup a notepad active data and write to that?  Why is this so complicated?  I can't use a visual test for this, so please, .NET script help is much appreciated.

0 Likes
2 Solutions

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Why is it so hard to capture timings and write them out line by line into a notepad file in a .NET script? Seems so simple but I cannot find an answer.

Jump to solution

You can likely use an entirely Active Data solution for this task.

Add a column for the actual value to your Active Data sheet. This column will be used to store the actual value retrieved from your web application, which can be verified against the expected value at a later point. Here is a very basic code outline of how to update an ActiveData sheet with the actual value and then verify that the "actual" values captured match the "expected" values:

Dim ad As ActiveData = Workbench.LoadActiveData("DemoAD")

Dim row As ActiveDataRow
Dim sActual As String

'Set the Actual value
For Each row In ad
     row.SetString("Actual", _desktop.DomElement("//SPAN").GetText())
Next

'Save the active data
ad.Save()

'Verify Expected and Actuals are the same
For Each row In ad
     Workbench.Verify(row.GetString("Expected"), row.GetString("Actual"))
Next

Let me know if this helps.

-Robert

0 Likes
Micro Focus Contributor
Micro Focus Contributor

RE: Why is it so hard to capture timings and write them out line by line into a notepad file in a .NET script? Seems so simple but I cannot find an answer.

Jump to solution

Try the following sample script, it creates a text file (or appends to an existing file).

Imports System.IO

  Public Module Main
  Dim _desktop As Desktop = Agent.Desktop

  Public Sub Main()

    ' Create a strings to write out.
    Dim csv = "hello,world,123,456"
    Dim csv2 = "world,Hello,456,123"
  
    ' Set the output file name to a file in My Documents 
    Dim fileName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\WriteLines.csv"
  
    ' Create a new file or append to an existing file.
    Dim sw As StreamWriter = Nothing
    If Not File.Exists(fileName) Then
      ' Create a file to write to.
      sw = File.CreateText(fileName)
    Else
      ' Existing file
      sw = New StreamWriter(fileName)
    End If
  
    sw.WriteLine(csv)
    sw.WriteLine(csv2)
  
    sw.Flush()
  End Sub
End Module


//*eggbox
0 Likes
8 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Why is it so hard to capture timings and write them out line by line into a notepad file in a .NET script? Seems so simple but I cannot find an answer.

Jump to solution

You can likely use an entirely Active Data solution for this task.

Add a column for the actual value to your Active Data sheet. This column will be used to store the actual value retrieved from your web application, which can be verified against the expected value at a later point. Here is a very basic code outline of how to update an ActiveData sheet with the actual value and then verify that the "actual" values captured match the "expected" values:

Dim ad As ActiveData = Workbench.LoadActiveData("DemoAD")

Dim row As ActiveDataRow
Dim sActual As String

'Set the Actual value
For Each row In ad
     row.SetString("Actual", _desktop.DomElement("//SPAN").GetText())
Next

'Save the active data
ad.Save()

'Verify Expected and Actuals are the same
For Each row In ad
     Workbench.Verify(row.GetString("Expected"), row.GetString("Actual"))
Next

Let me know if this helps.

-Robert

0 Likes
TrntGty1 Absent Member.
Absent Member.

RE: Why is it so hard to capture timings and write them out line by line into a notepad file in a .NET script? Seems so simple but I cannot find an answer.

Jump to solution

Yes, thank you, this is definitely going to help me with bits of my script.  The MAIN thing I need to do is have the script creating a text file.

More simply, my question is this:  How do you write comma delimited lines into a .txt file.  Alternatively, how do you write into an excel file?

The problem I have is when I make this comparison, I need this comparison to be output into a text file so managers can review.  Please help, I have no idea why it is so complex to simply write lines into a txt file!  Please help!

0 Likes
Micro Focus Contributor
Micro Focus Contributor

RE: Why is it so hard to capture timings and write them out line by line into a notepad file in a .NET script? Seems so simple but I cannot find an answer.

Jump to solution

This should help:

community.microfocus.com/.../18385.fileio-with-silktest-workbench.aspx

It's simply a wrapper round StreamReader and StreamWriter, but you can read/write anything to a text or ini file with it.

0 Likes
Micro Focus Contributor
Micro Focus Contributor

RE: Why is it so hard to capture timings and write them out line by line into a notepad file in a .NET script? Seems so simple but I cannot find an answer.

Jump to solution

Try the following sample script, it creates a text file (or appends to an existing file).

Imports System.IO

  Public Module Main
  Dim _desktop As Desktop = Agent.Desktop

  Public Sub Main()

    ' Create a strings to write out.
    Dim csv = "hello,world,123,456"
    Dim csv2 = "world,Hello,456,123"
  
    ' Set the output file name to a file in My Documents 
    Dim fileName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\WriteLines.csv"
  
    ' Create a new file or append to an existing file.
    Dim sw As StreamWriter = Nothing
    If Not File.Exists(fileName) Then
      ' Create a file to write to.
      sw = File.CreateText(fileName)
    Else
      ' Existing file
      sw = New StreamWriter(fileName)
    End If
  
    sw.WriteLine(csv)
    sw.WriteLine(csv2)
  
    sw.Flush()
  End Sub
End Module


//*eggbox
0 Likes
TrntGty1 Absent Member.
Absent Member.

RE: Why is it so hard to capture timings and write them out line by line into a notepad file in a .NET script? Seems so simple but I cannot find an answer.

Jump to solution

I am going to try this here right now, thank you so much!!

I will report back with my findings.

0 Likes
TrntGty1 Absent Member.
Absent Member.

RE: Why is it so hard to capture timings and write them out line by line into a notepad file in a .NET script? Seems so simple but I cannot find an answer.

Jump to solution

Oh man, this did the trick for creating my file!   Thank you thank you!  

Quick question.  This script needs to loop, when I set it up to loop, I got this error:  Do you know what might have caused it?

If I want this to be a part of a For loop, would I need to remove or change anything?

Will I need to remove "Flush()"?

0 Likes
TrntGty1 Absent Member.
Absent Member.

RE: Why is it so hard to capture timings and write them out line by line into a notepad file in a .NET script? Seems so simple but I cannot find an answer.

Jump to solution

Thank you so much.  I am meeting with management to see if delivering an excel file in place of the usual .txt would suffice.  I really appreciate it.

0 Likes
garecanbp Contributor.
Contributor.

RE: Why is it so hard to capture timings and write them out line by line into a notepad file in a .NET script? Seems so simple but I cannot find an answer.

Jump to solution

Hi, I tried your code but receive this error

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.