Check for Object that Does Not Exists in TruClient

Show us your love by sharing this post.

From the past many months, I have been working extensively on Micro Focus LoadRunner TruClient protocol. TruClient helps to measure the end-to-end performance which is an apt solution for modern web applications which are built using modern javascript libraries such as Angular, React etc. In this blog, I am going to share how to check for object that does not exist in TruClient which will help you as well in your project.

Why you need to check for object that does not exist?

You could ask why there is a need to check for object that does not exist in TruClient. I can give you umpteen examples, let me be short.

Assume that you are testing an Add To Cart action. Once you click on the button, you will get a spinner icon, let’s call it as loaderGIF as shown below.

Loader GIF

Now assume again that one of the builds is broken, micro-services messed up and your response time shoots up, loaderGIF spins up for more than 10 seconds.

In this case, you could use Wait Until <object> that does not exist step in your TruClient step. Of course, you can use Wait Until <object> exist for the cart page objects as well. Both cases are possible. If you would like to implement that the object does not exist, read further.

Demo

I have added a couple of lines of code in the below W3Schools example. Here is the link https://www.w3schools.com/code/tryit.asp?filename=G269FJAU8S54

Below code extended the HTML and JavaScript which removes the element loader.

var elem = document.getElementById("loader");
elem.parentNode.removeChild(elem);

Here is the complete code which runs on W3Schools.

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
/* Center the loader */
#loader {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 1;
  width: 150px;
  height: 150px;
  margin: -75px 0 0 -75px;
  border: 16px solid #f3f3f3;
  border-radius: 50%;
  border-top: 16px solid #3498db;
  width: 120px;
  height: 120px;
  -webkit-animation: spin 2s linear infinite;
  animation: spin 2s linear infinite;
}

@-webkit-keyframes spin {
  0% { -webkit-transform: rotate(0deg); }
  100% { -webkit-transform: rotate(360deg); }
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Add animation to "page content" */
.animate-bottom {
  position: relative;
  -webkit-animation-name: animatebottom;
  -webkit-animation-duration: 1s;
  animation-name: animatebottom;
  animation-duration: 1s
}

@-webkit-keyframes animatebottom {
  from { bottom:-100px; opacity:0 } 
  to { bottom:0px; opacity:1 }
}

@keyframes animatebottom { 
  from{ bottom:-100px; opacity:0 } 
  to{ bottom:0; opacity:1 }
}

#myDiv {
  display: none;
  text-align: center;
}
</style>
</head>
<body onload="myFunction()" style="margin:0;">

<div id="loader"></div>

<div style="display:none;" id="myDiv" class="animate-bottom">
  <h2>Tada!</h2>
  <p>Some text in my newly loaded page..</p>
</div>

<script>
var myVar;

function myFunction() {
  myVar = setTimeout(showPage, 3000);
}

function showPage() {
  document.getElementById("loader").style.display = "none";
  document.getElementById("myDiv").style.display = "block";
  
  var elem = document.getElementById("loader");
elem.parentNode.removeChild(elem);
}
</script>

</body>
</html>

TruClient Script

Below is the snapshot of the TruClient script which demonstrates the object does not exist purpose.


TruClient Script

Step 1

Navigate to https://www.w3schools.com/code/tryit.asp?filename=G269FJAU8S54.

Note: I prefer it to run in TruClient Browser.

Step 2

TruClient clicks on Run button.

Run button

Step 3

Loader image displays for couple seconds. Meanwhile, TruClient looks for the absence of the object //div[@id=”loader”] as shown below.

I prefer to use XPath to identify the objects.


Loader

Step 4

Verifies the text after successful loading.


successful loading

How to check for an Object that Does Not Exists in TruClient?

Go to Toolbox > drag and drop Wait for Object under Functions as shown below.

Wait for Object

Next step is to choose an object which needs to wait. Just click on Click to choose an object as shown below, then click on the object.

Click to choose an object

You could click on any object and then change the Object ID Method to XPath and add //div[@id=”loader”]

Now, click on exists and change the Arguments – Existsto false as shown below. This will check for the absence of an object.

Wit Until – Check for an Object that Does Not Exists in TruClient

Need to implement the above approach quickly?

Conclusion

Checking for an object that does not exist in TruClient helps you to implement the alternative approach to verify your business scenario.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

New Year. New Hope. Learn TruWeb. 78% OFF for Limited Time of my Udemy course..BUY NOW