https://www.qatechies.com

How to create simple custom xmodule in Tosca

Tosca Excel Engine

How to create simple custom xmodule in Tosca


Welcome to this Post – “How to create simple custom xmodule in Tosca” discusses about the Tosca Custom xmodules and how to create one. We also focus on some frequently asked Tosca Custom Xmodule related questions which you might be facing in your projects. The complete post is divided into small sections where we are discussing the problem statements, frequently discussed feasibility questions and concepts and then focusing on the Tosca custom xmodule creation. So, go ahead and enjoy reading…

Well if you are looking for solution on creating custom xmodule which are not being provided by Tosca Commander but you require them with functionality intended to support in your project then you are looking at right post.

How to create custom xmodule in Tosca?

Before we dig deeper into the way of creation, there are few points you should focus on first. These below points can be different based on project, test planning, etc should be considered before implementing the custom control and xmodule:

 

  1. Is it really going to help in your project?
  2. Have you tried all the given modules to solve your problem statement?
  3. Have you listed those approach and checked with your architect?
  4. Have you identified the technology with which the custom control or xmodule needed to be developed?
  5. Do you have enough time in planning for developing custom control or xmodule?
  6. Do you possess development skillset for the required control or module in question? Or does it require developer from DevTeam to coordinate with you? Etc.

Well the questions can be many, based on scenario you have.

So always try to evaluate the situation based on planning and if possible try discussing such scenarios as early as possible so that no more delay occurs in sprint.


Getting to know your problem statement

Now we will follow an example and we are going to build our first custom xmodule. This problem statement is very common and often requires people to go with a workaround of creating 10+ steps combining various operations of buffer module, do-while steps, string modules etc. and finally creating library of that.

Believe me, in an Agile sprint we do not have that much time of creating these steps or library modules. Of course, it will help people around the circle but if there is change in individual module version, like Tosca has been upgraded, in that case your library module needs upgrade too.

The better way for such problem statement is to create a custom xmodule and deploy the dll into Tosca home directory.

And, if in future you need upgrade the only thing you will require is to rebuild your solution. That’s it!

 

So let’s try to analyze such situation with given below problem statement.

Problem statement:

Consider that you require to break a string into many parts and simultaneously you want all broken parts of the main string should get stored into number of buffers. The parts should contain only alphabets.

Note: In real world such cases do come to us often. For example, an order number containing both alphabets and numeric values. And part of it you require in your next step as an input.

For example:

Suppose my string is “ABCDE456FGHIJKL789MNOPQ”. I want it to be broken such that I always get parts which has alphabets. So my final result should look like:

“ABCDE” “FGHIJKL” “MNOPQ”

 

 

Ways of solving it:

Well there are lots of ways, but keeping in mind the performance I will point only 2 major ways:

  1. You can use substring to extract the part from main string and store in buffer.
  2. You can use regular expression.

Believe me the second way is always fast in such cases. So, in this case the regular expression will be like “\d+”. The values which we will receive with this expression or pattern is shown below:

“ABCDE” “FGHIJKL” “MNOPQ”

It means we will get 3 values and these needs to be stored in buffers automatically at the very time there was a match. But how this is going to happen, right!

Let’s start by creating an XModule in your module section:

Steps:

  1. Right click on Module folder and select “Create Xmodule”.
  2. Give name like “Splitter”
  3. Create your XModule attributes like:
  4. Initbuffername – this will be used for setting the names of new buffers, i.e. buffer1, buffer2 so “buffer” is what you should enter.
  5. valuestring – this will be used for entering the main string or your actual string in question.
  6. Regexval – this is a Boolean value indicating the following value in splitstring attribute is actual regex pattern or numeric value based on which the extraction should be done.
  7. Splitstring – can have either regex pattern or numeric values like “\d+” or 3,5,3,7.
  8. Set all attributes with configuration parameter: Parameter =true
  1. Set Xmodule “Splitter” with configuration parameter: SpecialExecutionTask = <your class name> and Engine = <your dll name >.
  2. Set “DefaultActionMode” to “Input” for all attributes.

That’s it! You are half way done.The only thing require here is now that you have to write c# code and implement the method with your desired logic.

Steps In VSTS:

  1. Create c# class file with name “buffersplitter.cs
  2. Use following directives in this class and add their references:
//assemblies or directives to include

using Tricentis.Automation.AutomationInstructions.Configuration;

using Tricentis.Automation.AutomationInstructions.Dynamic.Values;

using Tricentis.Automation.AutomationInstructions.TestActions;

using Tricentis.Automation.Creation;

using Tricentis.Automation.Engines;

using Tricentis.Automation.Engines.SpecialExecutionTasks;

using Tricentis.Automation.Engines.SpecialExecutionTasks.Attributes;

using Tricentis.Automation.Execution.Results;
  1. Implement SpecialExecutionTaskEnhanced in your class.
  2. Now define and implement the method ExecuteTask.

Once this is done you need to deploy the dll into folder “C:\Program Files (x86)\TRICENTIS\Tosca Testsuite\”. This deployment can be done via Build tab in properties of your project.

Now you restart your Tosca Commander and use the custom XModule in your test case, pass the following values:

Initbuffername = RegParts

Valuestring = ABCDE456FGHIJKL789MNOPQ

Regexval=true

Splitstring=”\d+”

Now run the test case in the scratchbook and check your results you should see 3 buffers as shown below:

Simple Custom Controls or Xmodules Usage
Simple Custom Xmodules Usage

 


Conclusion

What we were expecting was all the names of newly created buffers along with their values should be shown and it is quite evident from the above image that the “LogInfo” column clearly shows the names of new buffers along with the values it has set.

So we have created the solution around our problem statement correctly.

 

Well, this brings me to the end of the discussion where we have discussed some concepts as well as interview questions.I really hope you enjoyed reading the post. If you have any doubt on this please feel free to add your comment below.


If you would like to keep track of further articles on TOSCA. I recommend you to SUBSCRIBE by Email and have new articles sent directly to your inbox.

3 Replies to “How to create simple custom xmodule in Tosca”

  • I like this explanation . I wish I could see the complete code for this SET so that later on I could start modifying and create SET on my own .
    TOSCA support portal doesn’t have much detailed explanations for beginners to start creating SET on their own.

Leave a Reply

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

advanced-floating-content-close-btn
https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5034726663464946 (adsbygoogle = window.adsbygoogle || []).push({});
advanced-floating-content-close-btn 
*************************** Do you want to learn TOSCA? Do you want to excel in Career? Try my New Courses: 1. Tricentis Tosca and Working with Excel   2. Tricentis Tosca and UI Automation Great News!!   Price has been slashed down for limited period of time.So Hurry!!! Click The Shown Links and Enjoy Learning. ***************************
 
error: Content is protected !!