Skip to main content

Posts

Showing posts from 2016

Logging in Selenium - To File

In my previous post I explained you how you can configure log4net in your project to do logging to console with example. Now, in this post I will be explaining how we can configure log4net to log to file instead of console. As we already have working logs to console from our TestFramework so logging to file doesn't take much efforts. You just need to follow below steps and you are done. Configuring log4net to log to file Step 1 : Add an " app.config " file in your UITests project with content as shown below: Step 2:   Change configurator in Configure method of Log class That's it. Now, when you will run the test it will log to console as well as file named " Test.log ". This file can be found at \TestFramework\UITests\bin\Debug location in you project folder. As you saw, we just added app.config file and then changed the configurator in order to log to file. Earlier we used "BasicConfigurator.Configure()" which writes logs to cons...

Logging in Selenium

Any application is incomplete until it's activities are traceable. Here comes the use of logging. By logging important actions you can later on track anything you want especially when there are some error situations. It becomes easy to debug the issues if logs are generated properly. Similarly, it is very important that our automation framework generates logs so that whenever any test fails, we can track the issue by tracing it's logs. In this post, I will be explaining you how we can log using log4net in selenium. Before using methods of this library we need to configure this to our application. Let's do this first then. Configuring log4net in selenium: First of all you need to download this library so that this can be used. You can read about log4net and then download it from this link and save the dll file after extracting it to folder that is under your project folder. After downloading this library you need to add references of this in you project. To do ...

SELENIUM: Test Structure - Use of Different Attributes

As I mentioned in my previous post that in this post we will be discussing about test structure that we will are writing. Here I will be explaining in brief different types of attributes that can be used while writing our tests. Till now we have just used one attribute i.e. [TestMethod] which contains the test to be executed. There are other important attributes that can be used during tests to make tests well organized. Few of the attributes are as given below: [ClassInitialize] [ClassCleanup] [TestInitialize] [TestCleanup] [AssemblyInitialize] [TestMethod] [TestClass] [ClassInitialize] attribute can be used with a method that you want to execute before intialization of a class. So, let's suppose there are five tests in a test class then the method having [ClassInitialize] attribute will run only once for this class before running all the tests. [ClassCleanup] attribute can be used with a method that you want to execute after all the tests in the class ar...

SELENIUM: Next Test to Framework

Now, let's add one more test to our framework and see how it grows. In my previous post we created one basic test which tests that user can successfully login to the application. Let's add next test to same login tests category which will test that user cannot login to application with incorrect credentials and then develop corresponding needed framework. Second test to Framework For this we will create test and corresponding framework for below steps: User tries to login with incorrect credentials Verify that the login error message is visible  As we have already created a LoginTests class under UITests project so, we don't need to add another class as category of this test is same. Just add below test method to this class. Here, we have created one test method as " User_Cannot_Login_With_Invalid_Credentials ". In this method again we have added required steps to test our scenario. First and second steps are similar to previous test. Here,...

SELENIUM: Creating a Basic Test

By now you must be pretty confident of what actually selenium is, how we can set up an environment to build an automation framework and what kind of things we should have in our mind before we start building a framework. Also, you know few of the basic concepts too. I think now it's a good time to start building our framework. The approach I will be using to build the framework is that I will be just creating a basic test first. After that by the course of time I will be adding more tests in it and in this way our framework will start growing in size with each test added. I will be doing lots of refactoring as and when required so that the framework remains well structured and easy to use. As to build a framework we need an application, I will be using WordPress for this purpose. You can use any application but if you need to get a start on WordPress too you can download and setup from this link . Instead of adding all the required things in the framework what I will ...

SELENIUM: Some Useful Facts

Before we start designing a framework, there are few facts that we should always remember. It is not important what you have designed, it is more important that how good your product is. Also, this kind of analysis should always be done in the beginning so that you don't have to devote extra time and efforts for it later. It is always good to fix something in beginning than worrying about it later when it has become a big issue and become difficult to locate the issue. It's not like that we won't be able to fix it, we will definitely fix it but with more cost and efforts. Let's go through few of these facts. Layers in Framework You should always keep in mind the layers that should be there in the framework you are designing. Layers to be created generally varies application to application that you are creating but most of the frameworks contains below layers often. In above picture, there is workflow layer at the top. Workflows can be think of as somet...

SELENIUM: Page Object Model

As now we have created our first hello selen ium test successfully , I think it is the good time to know something about architec ture of fr amework that we are going to design. It is always good to know what actually hap pens when you do something as it gives you a better understanding of it and you can easily know what you need to do, how you need to do and where could be the f ault if something wrong happens. So, let's go th rough it in brief. Page Object Model  The basic idea of this page object model is that we have a class for each page or a logical part in our application and it contains methods in it which represents the functionality of th is page. Further, tests interacts with the corresponding page class and access its methods as required.  In above picture there is a login page that is there in our application and corresponding to this login page there is a LoginPage class having all the method s defined i n it which corresponds to the va...

"Hello Selenium"

Now, as we have already setup the required environment, let's just start with a hello world test with selenium. In this let's just write a basic test to make sure that our environment is working properly. For this hello selenium test we will be automating below test: Navigate to " https:// www.google.com  " Write "Hello selenium" in search box Press search button Below are the code snippets: Test class UnitTest1 containing required test. Here in this class, at the top I have used two statements i.e.     using Microsoft.VisualStudio.TestTools.UnitTesting;     using TestFramework; First using statement is required in for writing unit tests and second using statement is required so that we can access methods from class under TestFramework namespace. There is [TestClass] attribute used with this class. This is required so that tests written in this class can be recognized. If you miss this attribute then your tests are not going ...

Getting Started with Selenium

Getting environment ready: Before we can start writing scripts with selenium lets just see how to get the environment ready for this. I hope that you are already having visual studio installed on your system. Instead of just starting basic things with console program, we will be creating an environment which can later be used to build framework and write tests, otherwise we have to setup the environment again later when we start building framework. So, here it goes... Open visual studio Select File->New->Project as shown below: From new project window, Select visual c# then Select Class Library Enter name, select location and click ok as shown below: Now in solution explorer, under your added project, right click on References Select Manage NuGet Packages... option from window as shown below: From NuGet window install Selenium.WebDriver and Selenium.Support packages as shown below:  Now, add another project i.e. a u...

About Selenium

Let's start with a basic information about Selenium . Selenium: It is basically a tool or framework that is used to automate web browsers. By using selenium you can automate a lots of web browsers like Firefox, IE, Chrome etc.  It is possibly most widely used open source solution. Sel enium is basically a set of different tools with different purpose and role . E.g. Selenium IDE Selenium 1 (Selenium RC) Selenium 2 ( Selenium Webdriver) Selenium-Grid Sel enium webdriver is the one which we will be using during this course. It supports fol lowing bro wsers: Google Chrome Internet Explorer Firefox Safari Opera HtmlUnit phantomjs Android iOS So, it is the one that allows you to automate these web browsers. If we talk little bit technically, then it is basically an API for web browsers. Using this you can program web browsers in a way that you want them to do. If you want to learn more about selenium then you can go through this link . Archite...

SELENIUM: Technology Stack

Before we sta rt this automation framew ork course, we should know what actually we are going to use for this so that we can have all th ose ready beforehand.   This is the post, where you can find the technologies used for this whole process. Further , in t his blog, I will be writing the course to create a n automation framework so I will be focusing more on webdriver compon e nt of selenium and less on other components like selenium ide, RC etc. I can cover these under "Interesting facts" topic later during the course. I will also try to cover some of the other inter esting topics in this which cannot be covered in course. So, let's go through the technologies which I will be using during this course. I will be using Selenium webdriver  as automation tool for building framework,  C# as a programing language, MSTest testing framework for writing tests and visual studio as development tool. So, it is assumed that you have at least basic knowle...