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();                                       
                                }
}

Selenium best basics

Hi Folks,

For selenium all concept, I found good article on Guru 99 site. I tried with most of the examples and all are well explained and worked.

Cheers.
TJ

Monday, January 20, 2020

Knowledge BoT using asp.net


Recently come across the good article on chat bot using ASP.net as well as with WCF, which we have used for the simple knowledge base for the team, which reduce the onboarding time of resources.



Cheers. 

TJ

Tuesday, January 14, 2020

OOPs Concept

Hey folks,

Never thought after so many years later, I need to recall the basic OOPS again. Here I get help from “https://beginnersbook.com/” and would like to say thanks for it. Below reference is taken from it and all credit of this article is given tohttps://beginnersbook.com/. I have just put it here the content for easy reference of mine and others. More details you can find on “https://beginnersbook.com/”.

Basic OOPS

Object: is a bundle of data and its behavior(often known as methods). Objects have two characteristics: They have states and behaviors.
Example: Object: Car
State: Color, Brand, Weight, Model
Behavior: Break, Accelerate, Slow Down, Gear change.
Characteristics of Objects:
1.       Abstraction- Abstraction is a process where you show only “relevant” data and “hide” unnecessary details of an object from the user
2.       Encapsulation- Encapsulation simply means binding object state(fields) and behavior(methods) together. If you are creating class, you are doing encapsulation.
3.       Message passing- A single object by itself may not be very useful. An application contains many objects. One object interacts with another object by invoking methods on that object. It is also referred to as Method Invocation
class can be considered as a blueprint using which you can create as many objects as you like.
Constructor looks like a method but it is in fact not a method. It’s name is same as class name and it does not return any value. We can also have parameters in the constructor, such constructors are known as parametrized constructorsThere are three types of constructors: Default, No-argconstructor and Parameterized.

Object Oriented Programming features

Abstraction

Abstraction is a process where you show only “relevant” data and “hide” unnecessary details of an object from the user. 

Encapsulation

Encapsulation simply means binding object state(fields) and behavior(methods) together. If you are creating class, you are doing encapsulation. the benefit of encapsulation in java programming at some point of time, if you want to change the implementation details of the class  you can freely do so without affecting the classes that are using it.

Inheritance

The process by which one class acquires the properties and functionalities of another class is called inheritance. Inheritance provides the idea of reusability of code and each sub class defines only those features that are unique to it, rest of the features can be inherited from the parent class.
1.       Inheritance is a process of defining a new class based on an existing class by extending its common data members and methods.
2.       Inheritance allows us to reuse of code, it improves reusability in your java application.
3.       The parent class is called the base class or super class. The child class that extends the base class is called the derived class or sub class or child class.
Note: The biggest advantage of Inheritance is that the code in base class need not be rewritten in the child class.
The variables and methods of the base class can be used in the child class as well
class A extends B
{
}
Note: Multi-level inheritance is allowed in Java but not multiple inheritance
Types of Inheritance:
Single Inheritance: refers to a child and parent class relationship where a class extends the another class.
Multilevel inheritance: refers to a child and parent class relationship where a class extends the child class. For example class A extends class B and class B extends class C.
Hierarchical inheritance: refers to a child and parent class relationship where more than one classes extends the same class. For example, class B extends class A and class C extends class A.
Multiple Inheritance: refers to the concept of one class extending more than one classes, which means a child class has two parent classes. Java doesn’t support multiple inheritance
Most of the new OO languages like Small Talk, Java, C# do not support Multiple inheritance. Multiple Inheritance is supported in C++.

Polymorphism

Polymorphism is a object oriented programming feature that allows us to perform a single action in different ways.Types of Polymorphism
1) Static Polymorphism
2) Dynamic Polymorphism

Static Polymorphism:

Polymorphism that is resolved during compiler time is known as static polymorphism. Method overloading can be considered as static polymorphism example.
Method Overloading: This allows us to have more than one methods with same name in a class that differs in signature.
Note: When I say method signature I am not talking about return type of the method, for example if two methods have same name, same parameters and have different return type, then this is not a valid method overloading example. This will throw compilation error.

Dynamic Polymorphism

It is also known as Dynamic Method Dispatch. Dynamic polymorphism is a process in which a call to an overridden method is resolved at runtime rather, that’s why it is called runtime polymorphism.

IS-A & HAS-A Relationships

A Car IS-A Vehicle and HAS-A License then the code would look like this:
Abstract method:
1) A method that is declared but not defined. Only method signature no body.
2) Declared using the abstract keyword
3) Example :
abstract public void playgame();
5) Used to put some kind of compulsion on the class who inherits the class has abstract methods. The class that inherits must provide the implementation of all the abstract methods of parent class else declare the subclass as abstract.
6) These cannot be abstract
·         Constructors
·         Static methods
·         Private methods
·         Methods that are declared “final”
Abstract Class
An abstract class outlines the methods but not necessarily implements all the methods.
abstract class A{
   abstract void myMethod();
   void anotherMethod(){
      //Does something
   }
}
Note 1: There can be some scenarios where it is difficult to implement all the methods in the base class. In such scenarios one can define the base class as an abstract class which signifies that this base class is a special kind of class which is not complete on its own.
A class derived from the abstract base class must implement those methods that are not implemented(means they are abstract) in the abstract class.
Note 2: Abstract class cannot be instantiated which means you cannot create the object of abstract class. To use this class, you need to create another class that extends this abstract class provides the implementation of abstract methods, then you can use the object of that child class to call non-abstract parent class methods as well as implemented methods(those that were abstract in parent but implemented in child class).
Note 3: If a child does not implement all the abstract methods of parent class(the abstract class), then the child class must need to be declared abstract.

Interfaces in Java

An interface is a blueprint of a class, which can be declared by using interface keyword. Interfaces can contain only constants and abstract methods (methods with only signatures no body).Like abstract classes, Interfaces cannot be instantiated, they can only be implemented by classes or extended by other interfaces. Interface is a common way to achieve full abstraction in Java.
Note:
1.       Java does not support Multiple Inheritance, however a class can implement more than one interfaces
2.       Interface is similar to an abstract class but it contains only abstract methods.
3.       Interfaces are created by using interface keyword instead of the keyword class
4.       We use implements keyword while implementing an interface(similar to extending a class with extends keyword)
Interface: Syntax
class ClassName extends Superclass implements Interface1, Interface2, ....
Note:
1.       All methods in an interface are implicitly public and abstract. Using the keyword abstract before each method is optional.
2.       An interface may contain final variables.
3.       A class can extend only one other class, but it can implement any number of interfaces.
4.       When a class implements an interface it has to give the definition of all the abstract methods of interface, else it can be declared as abstract class
5.       An interface reference can point to objects of its implementing classes
Generalization and Specialization:
In order to implement the concept of inheritance in an OOPs, one has to first identify the similarities among different classes so as to come up with the base class.
This process of identifying the similarities among different classes is called Generalization. Generalization is the process of extracting shared characteristics from two or more classes, and combining them into a generalized superclass. Shared characteristics can be attributes or methods.
In contrast to generalization, specialization means creating new subclasses from an existing class. If it turns out that certain attributes or methods only apply to some of the objects of the class, a subclass can be created.

Access Specifiers

Well, you must have seen public, private keyword in the examples I have shared above. They are called access specifiers as they decide the scope of a data member, method or class.
There are four types of access specifiers in java:
public: Accessible to all. Other objects can also access this member variable or function.
private: Not accessible by other objects. Private members can be accessed only by the methods in the same class. Object accessible only in class in which they are declared.
protected: The scope of a protected variable is within the class which declares it and in the class which inherits from the class (Scope is class and subclass).
Default: Scope is Package Level. We do not need to explicitly mention default as when we do not mention any access specifier it is considered as default.

Method Overloading

Method Overloading is a feature that allows a class to have more than one method having the same name, if their argument lists are different. It is similar to constructor overloading in Java, that allows a class to have more than one constructor having different argument lists.

Three ways to overload a method

In order to overload a method, the argument lists of the methods must differ in either of these:
1. Number of parameters. add(int, int), add(int, int, int)
2. Data type of parameters. add(int, int), add(int, float)
3. Sequence of Data type of parameters. add(int, float),add(float, int)
Method overloading is an example of Static Polymorphism
Points to Note:
1. Static Polymorphism is also known as compile time binding or early binding.
2. Static binding happens at compile time. Method overloading is an example of static binding where binding of method call to its definition happens at Compile time

Method overriding

Declaring a method in sub class which is already present in parent class is known as method overriding. Overriding is done so that a child class can give its own implementation to a method which is already provided by the parent class. In this case the method in parent class is called overridden method and the method in child class is called overriding method. The main advantage of method overriding is that the class can give its own specific implementation to ainherited method without even modifying the parent class code.
This is helpful when a class has several child classes, so if a child class needs to use the parent class method, it can use it and the other classes that want to have different implementation can use overriding feature to make changes without touching the parent class code
Method Overriding is an example of runtime polymorphism. When a parent class reference points to the child class object then the call to the overridden method is determined at runtime, because during method call which method(parent class or child class) is to be executed is determined by the type of object. This process in which call to the overridden method is resolved at runtime is known asdynamic method dispatch. Note: In dynamic method dispatch the object can call the overriding methods of child class and all the non-overridden methods of base class but it cannot call the methods which are newly declared in the child class.

Rules of method overriding

1.       Argument list: The argument list of overriding method (method of child class) must match the Overridden method(the method of parent class). The data types of the arguments and their sequence should exactly match.
2.       Access Modifier of the overriding method (method of subclass) cannot be more restrictive than the overridden method of parent class. For e.g. if the Access Modifier of parent class method is public then the overriding method (child class method ) cannot have private, protected and default Access modifier, because all of these three access modifiers are more restrictive than public.
  1. private, static and final methods cannot be overridden as they are local to the class. However static methods can be re-declared in the sub class, in this case the sub-class method would act differently and will have nothing to do with the same static method of parent class.
  2. Overriding method (method of child class) can throw unchecked exceptions, regardless of whether the overridden method(method of parent class) throws any exception or not. However the overriding method should not throw checked exceptions that are new or broader than the ones declared by the overridden method. We will discuss this in detail with example in the upcoming tutorial.
  3. Binding of overridden methods happen at runtime which is known as dynamic binding.
  4. If a class is extending an abstract class or implementing an interface then it has to override all the abstract methods unless the class itself is a abstract class.
The super keyword is used for calling the parent class method/constructor. super.myMethod() calls the myMethod() method of base class while super() calls the constructor of base class.

Overloading vs Overriding in Java

1.       Overloading happens at compile-time while Overriding happens at runtime: The binding of overloaded method call to its definition has happens at compile-time however binding of overridden method call to its definition happens at runtime.
2.       Static methods can be overloaded which means a class can have more than one static method of same name. Static methods cannot be overridden, even if you declare a same static method in child class it has nothing to do with the same method of parent class.
3.       The most basic difference is that overloading is being done in the same class while for overriding base and child classes are required. Overriding is all about giving a specific implementation to the inherited method of parent class.
4.       Static binding is being used for overloaded methods and dynamic binding is being used for overridden/overriding methods.
5.       Performance: Overloading gives better performance compared to overriding. The reason is that the binding of overridden methods is being done at runtime.
6.       private and final methods can be overloaded but they cannot be overridden. It means a class can have more than one private/final methods of same name but a child class cannot override the private/final methods of their base class.
7.       Return type of method does not matter in case of method overloading, it can be same or different. However in case of method overriding the overriding method can have more specific return type (refer this).
8.       Argument list should be different while doing method overloading. Argument list should be same in method Overriding.