Forum Discussion

jsayre's avatar
jsayre
Occasional Contributor
10 years ago
Solved

Calling Scripts in keyword tests as verification

In a series of my tests I am calling a script (code provided below) that verfies that a file exists in a specfic location. When I run these tests individually, by opening the test and running them with the run button at the top of the frame, they run perfectly fine. If I run it in the project suite, the verification fails even if the conditions are correct for the checkpoint within the script.



I have another question for anyone who has used scripts within their keyword tests. Is there a way to pass object data from a keyword test to a variable in a script? I want to pass the index number of the object that I am clicking (or name of an object) to a variable in a script so I can identify case that I need to run against that object.





function verify_Checkout()

{

  // Run function to set filepath

  // define_FileInfo();

  filepath = "C:\\dmslocal\\bridge\\smithfield_st_bridge";

  filename = "\\decks.dgn";

 

  // Test Debug - Check for filepath settings

  // Log.Message("File we are looking for\: " + filepath + filename);

 

  // Initialize the fileflag variable

  fileflag = aqFileSystem.Exists(filepath + filename)



  // Test Debug - Check for fileflag state

  // Log.Message("fileflag is " + fileflag);



  switch (fileflag) {

    case null :

      // Variable null'd - big issues

      Log.Message("Error has occured due to no state change")

      Log.Error(error1)

    break;

    case false :

       // Return false - file was not checked out

      Log.Message("File has not been found. Validate manually.")

      Log.Error(error2)

    break;

    case true :

      // Return true - File was checked out successfully

      Log.Message("File found Successfully. Proceed with Verification.")

      Log.Checkpoint("Success!")

    break;

    default :

      // Catch-all Error

      Log.Message("Nothing Written. Failed Test.")

      Log.Error(error1)

  }

}




  • Hi Jeremy,

     


    I can suggest the following to you: create a project variable with the Object type and set its value via the Set Variable Value operation. In the script, you can read this value via Project.Variables.<Name>.


     

2 Replies

  • jorgesimoes1983's avatar
    jorgesimoes1983
    Regular Contributor
    Like Tanya said, but using scripts:



    if (Project.Variables.VariableExists("name_of_your_variable") == false){

            Project.Variables.AddVariable("name_of_your_variable","Integer");

        }



    // after creating the variable you can store values like this:

    Project.Variables.name_of_your_variable = 1000;
  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)
    Hi Jeremy,

     


    I can suggest the following to you: create a project variable with the Object type and set its value via the Set Variable Value operation. In the script, you can read this value via Project.Variables.<Name>.