Posts

Showing posts from December, 2018

Interfaces and Abstract class

Image
Interfaces An Interface contains definitions for a group of related functionalities that a class can implement. Interfaces are contracts that your class should abide by.  Requirement Suppose you are creating a Web Automation tool, that targets IE and FF browser and supports the functionality of Opening and Closing the browser. Here you can notice that the functionalities will remain the same for both the browsers and also other new browsers which you can support in the future. We can have individual classes implementing these functionalities for respective browsers however we want all the classes to implement the functionalities(Opening and Closing Browser) which we defined earlier. So how can we force the class to implement the functionalities or contracts which we defined? Well that's where interfaces help  We can define an interface or contract with all our requirements and let other browser classes provide their implementations for those functionalities

C# Basics-Part 5(Working with strings)

Image
Most of the time in our automation project we will end up dealing with strings, that's the reason we will spend some time talking about strings in this lecture. Before we proceed we will talk about types first. Types in .Net can be either value or reference type Value types  They store data directly. example int, decimal etc. int   i   =   100 ; Here variable i stores the value 100 Reference types They store references to their data. example object, string etc string   str   =   "Hello I am amit" ;  Here str variable stores address of memory location which stores the actual "Hello I am amit" string; string The string is a reference type and is immutable ie contents of strings cannot be changed after a string is created. string   str   =   "Hello I am amit" ; char []   strLetters   =   {   '1' ,   'A' ,   'B'   }; string   str1   =   new   string ( strLetters ); We can use the new keyword to create stri

C# Basics-Part 4(Static Class and Singleton Design Pattern)

Image
Static Class A static class can be created using the static keyword and it can contain only static members. We cannot create an instance of a static class. Members of the static class can be accessed using the class name. So why you need static classes? Where do I use static classes? Static classes are used where there is a need for set methods that just operate on input parameters example utility classes, converter classes. Requirement Suppose your application under test requires your test script to enter details of user like the first name, last name etc and say this is a precondition of some of your test scripts. You can have a utility class that provides random data to the calling code, check below Important Point about static class Contains only static members Cannot be instantiated Use the class name to access the class members Is sealed, cannot be inherited from any class expect object Cannot contain instance constructor however they can contain a s

C# Basics-Part 3(Method Overloading,Method Chaining,Method Overriding)

Image
Methods are used in our code to implement common and specific behavior. We add a method to our class that defines the operations of the class. Today we will talk about some concepts around the methods, let's start Method Overloading Here we have multiple methods with the same name and purpose however with a different signature. They also have the same return type. Requirement Suppose in your automation project you want to write a common method that writes text to say textbox, text area etc. You have 2 choices here, you can clear the existing text and write a new one or you can append the new text to existing text if any. We can use method overloading here, we will add  2  SendKeys methods, one takes a single parameter(the text which one wants to write) and other method takes 2 parameters (text and the clearFlag, which can be used to clear/not clear the input before entering the text) Check below code We could have solved the req

C# Basics-Part 2(Namespaces,Properties,Constants and Read-Only Fields)

Image
Namespaces You would have recognized our class is wrapped in namespace block in our earlier lectures. Namespaces are used to organize classes in separate containers, you can consider them as an address of your class that helps the compiler to find the class. They are automatically added around the class and usually has the same name as the project they belong Here we can see Class1 is inside namespace NameSpaceDemo Imagine your application has multiple Class1 classes and now how do you guide the compiler on which one to pick, namespaces helps here. You can access the class using Namespace then dot the class name. NameSpaceDemo . Class1 Below one of the built-in namespace System . Console . WriteLine( "Test Namespace" ); Here System is the Namespace The console is the Class name WriteLine is the method name Properties Properties allow you to control the accessibility of class variables. Can be also called as guard access to the fields.

C# Basics-Part 1(Class,Objects,Constructors)

Image
In this lecture, we will talk about the basics of C#, topics which are needed to start our automation journey Before we start I assume you have installed Visual Studio Community or a similar version Class We have already talked about this in our previous lecture, however, we will write some code and we will talk about the same A class is a template for creating objects We will stick to our earlier example of DriverManager class for managing the browser namespace Configurations { /// Author- Amit Tambe /// Purpose- This class manages interaction with the browser class DriverManager { string browserType; public void Launch() { //Launch browser code goes here } } } Here we created a class with name DriverManager Here browserType variable holds string data and is called the class variable. Launch method launches the browser and this is the operation performed by the class In general, we can call