Thursday, February 6, 2020

Error Handling in Tosca

Error Handling and TOSCA Errors
There is a difference between Exceptions and Errors:
·     Exceptions
The term "exception" is used with:
Code exceptions: Use try-catch blocks to handle those.
Tosca exceptions which are not fatal to the overall execution and can be handled manually or ignored. A verification failure, for example, will be logged and can be ignored (the execution does not stop).
·     Tosca Error
A Tosca error is a severe failure which prevents the execution from being continued. The execution will stop and a Tosca error dialog window will be shown.
As unhandled exceptions stop execution immediately, an overall exception handling is a must for a stable Custom Engine. The Custom Engine should be splitted into two sections. The custom specific part, which handles the control logic and the Tosca specific part, which handles the communication with the Tosca Execution Framework. The custom specific part has to throw exceptions with error details, which are passed to the Tosca specific section. This section handles the exceptions with a try-catch block and converts it into an Tosca exception. The custom specific part has to provide as many information in the exception as possible to inform the user why it has occurred and what can/should be done to solve it.
Error types
In the handling of errors and exceptions, Tosca differentiates between three types of errors:
§  Verification-Failure: verification does not provide the expected results (e.g. an invoice total differs from the TestCase definition).
§  Dialog-Failure: the application wants to steer a control which does either not exist or is not in an operational state. Application errors like crashes or jams (i.e. if the application is not responding) also belong to this category.
§  User Abort: Abort of the test execution by the user.
For each of these error types, the handling at the time of the test execution can be defined via Tosca Executor: Tosca Executor is used for executing tests. TestCases can be executed by using either the Tosca Commander™ or by starting Tosca Executor. The Tosca Executor is opened via the Windows start menu Start->All Programs->Tricentis->Tosca Executor. After the default installation the TOSCAExecutor.exefile is located at: %TRICENTIS_HOME%\dll\.


Recover

With this option,Tosca tries to continue the test execution in spite of the error. In this case, generally an unwanted window is closed and after a few seconds of waiting, the verification is performed again. If the error cannot be resolved by Recover, it is recorded. This setting is useful for applications with a dynamic screen layout where a heavy load on the server may cause delays, for instance in HTML/web applications.
When the option recovery is selected, the following Recovery attempts can additionally be specified: It is possible to specify exactly whether and how often the recovery should be repeated on the different levels.
The number of the recovery attempts can be defined on three different levels:
  1. on the level of a control, this means on individual fields or screen elements
  2. on the screen level, this means individual modules or screens
  3. on the level of a TestCase, this means an individual TestCase
Ignore
This setting tries to continue the test execution. The error is logged but ignored for further execution.
Require manual input
In case of an error the test execution is aborted if this option is enabled. Tosca displays either the Tosca Manual Engine or an error dialog, depending on the selected behavior in theSettings dialog for the setting In case of halt. This exception setting may be useful for test case creation or attended test executions.
Execution Status Icon
During text execution, an execution status tray icon is displayed in the info area of the Windows task bar. At the beginning, the icon is white and gradually turns blue as the test progresses.
A right mouse click on the execution status tray icon opens a context menu with the following functions:
§  Halt Execution
The test execution is paused and can be continued later.
§  User Abort
The test execution is aborted. The test result is transferred to Tosca Commander™.
§  Terminate Execution
The process of Tosca Executor stops immediately. This action terminates the communication between Tosca Executor and Tosca Commander™ and should only be used ifUser Abort does not stop the test execution

Monday, January 27, 2020

Database testing using TOSCA

Hi folks,

Working with database using tosca is different experience and I found good article on basics.

Here, mention some key concepts for easy reference.

Interactions with databases are performed via SQL statements.
The test sequence consists of three major steps:
  1. Establishing a database connection
  2. Database operations
  3. Closing the database connection
Steering databases requires the use of specific Modules which are included in the Standard.tcesubset. These Modules are located in the folderStandard modules->TBox XEngines->Database.

Establishing a connection to a database - Module Open Connection
Open Connection can be used to establish a connection to a database. The connection is automatically defined as Current Connectionand is saved as a resource. Optionally, you can set the name of the resource via the parameterConnection name. If a connection already exists under the Connection name resource, no new connection is established. If no value is entered for the parameter Connection name, the value of the parameter DSN is used asConnection name. You can either use the DSNattribute for ODBC databases or theConnection string attribute for SQLite databases. The engine enables you to establish multiple database connections. The connection that was established most recently is always the current connection. Use the Module Current Connection to switch between open connections or to define a new Current Connection.
If you want to access SQLite databases via a connection string, use the ModuleAttributeConnection string. The required drivers are part of the Tricentis Tosca Testsuite standard installation.
Executing SQL statements - Module Run SQL Statement
Module Run SQL Statement can be used to steer data sets of one or more database tables. The engine accesses the database that is defined as Current Connection.
Specify the SQL statement to be executed in the parameter SQL Statement. Use the parameter Result Table to verify or buffer the content of a database table
The TBox Database Engine supports all read-onlyTBox table steering ActionModes. TheActionModes Input and Insert are however not supported.
The following ActionModes can be used to steer columns, rows and cells in tables:
ActionMode
Value
Description
Input
Entering a value
Verify
,
Verifying a value or a property
Constraint
This restricts the search
Buffer
Text->
Buffering the value of a cell
Use the ActionMode Select to select the table.
The following properties can be verified in addition to the general properties:
Property
Description
Available for
ColumnCount
Number of columns in the table
table
RowCount
Number of rows in the table
table
ColumnNumber
Index of the selected column. The value for a header column is 0 and the index for the remaining columns is relative to this column.
column
RowNumber
Index of the selected row. The value for a header row is 0 and the index for the remaining rows is relative to this row.
row
RawColumnNumber
Index of the selected column. It always starts at 1.
column
RawRowNumber
Index of the selected row. It always starts at 1.
row


Changing the connection to databases - Module Current Connection
Use the Module Current Connection to switch between established database connections. If the connection entered in the parameter Connection name exists, this is set as Current Connection.

Closing connections to a database - Module Close Connection
Use the Module Close Connection to close specific database connections. If the connection entered in the parameter Connection name exists, this is closed and the corresponding resource is deleted. If the closed connection was the Current Connection, the value zero is assigned to theCurrent Connection.
Closing the Current Connection may lead to errors when executing other Database EngineTestCases. Use the Modules Open Connection orCurrent Connection to define a new database connection as Current Connection. Any open connections will be closed automatically once theTestCase has been entirely executed.

Expert Module
The Expert Module enables you to handle your database statements via one single Module. The database connection is established via the parameters Connection nameDSNUser ID andPassword. This part of the Expert Modulecorresponds to the Module Open Connection. If you use the Current Connection you need not enter any values for the following parameters: DSN,User ID and Password
Use the parameter SQL Statement to execute SQL statements and verify data sets. The parameter Result Table enables you to steer the actions of your database table queries. For further details on the execution of SQL statements, please refer to Run SQL Statment.
Use the parameter Close Connection to specify whether the Current Connection should be closed or not. The parameter value is by default set to True.

Tosca cheat sheets

Connect database using Selenium

Package  htmldriver;                      
import  java.sql.Connection;                      
import  java.sql.Statement;                        
import  java.sql.ResultSet;                          
import  java.sql.DriverManager;               
import  java.sql.SQLException;                  
public class  SQLConnector{                                                       
                public static void  main(String[] args) throws  ClassNotFoundExceptionSQLException{                                                                                                                                                                                                   
                //Connection URL Syntax: "jdbc:mysql://ipaddress:portnumber/db_name"                          
                String dbUrl = "jdbc:mysql://localhost:3036/emp";                                                                        

                                                                //Database Username                   
                                                                String username = "root";             
                
                                                                //Database Password                     
                                                                String password = "test123";                                                      

                                                                //Query to Execute                         
                                                                String query = "select *  from employee;";           
                
                   //Load mysql jdbcdriver                           
                   Class.forName("com.mysql.jdbc.Driver");                                         
           
                               //Create Connection to DB                           
               Connection con = DriverManager.getConnection(dbUrl,username,password);
          
                               //Create Statement Object                          
                  Statement stmt = con.createStatement();                                                                         
       
                               // Execute the SQL Query. Store results in ResultSet                        
                               ResultSet rsstmt.executeQuery(query);                                                                                                             
         
                               // While Loop to iterate through all data and print results                             
                                while (rs.next()){
                               String myName = rs.getString(1);                                                                                                                                      
                            String myAge = rs.getString(2);                                                                                                  
                            System. out.println(myName+"  "+myAge);                           
                    }                       
                                                // closing DB Connection                            
                                              con.close();                                       
                                }
}