Showing posts with label selenium. Show all posts
Showing posts with label selenium. Show all posts

Thursday, March 15, 2018

Selenium C# - How to automatically download your file

If you want to check with Selenium that a specific file was downloaded, you need to start the new driver with some options, because the browser will show the Save popup that cannot be handled by Selenium.

You can do this by using this code in C# for Firefox and Chrome:




For IE, things are a little bit tricky, so you might try integrating TestSlack.White library and simulate the click on Save button with this library.

Later, you can create a test like this:


Happy testing and... make it green, becomes a dream :).


Wednesday, June 14, 2017

Selenium - Uploading file when input is invisible

Do you have problems simulating file upload in case the input is invisible?


You can make the element visible by using javascript in your code. Make the element visible and then call SendKeys to enter the path into the upload file input.



Happy testing and... make it green, becomes a dream :).


Monday, June 6, 2016

Selecting your Elements with XPath and CSSSelector

How my Desktop looks like :)?


This is an useful wall-chart from Rosetta Stone and Cookbook that covers popular technologies as XPath, CSS.

Some examples of how to use this wall-chart:

1. Use this By.CssSelector("g[id^='milestone']") to identify element below:


2. Use Instance.FindElements(By.CssSelector(".cellContent > a > div"), Ex)[i] to find all elements below: 


3. Use By.CssSelector(".ember-view.timeband-scale-format>div:first-of-type>div>ul>li>a")


Happy testing and... make it green, becomes a dream :).

Friday, May 27, 2016

Selenium Roadmap

We know that Selenium is an open source tool used to perform UI testing. Since July 2011, we started to use Selenium 2.
But we wonder what is the future of Selenium? The community developers are working to release Selenium 3.


The aim for Selenium 3 is to be "a tool user-focused automation of mobile and web apps". What does it mean? See this link to found out: https://seleniumhq.wordpress.com/2013/08/28/the-road-to-selenium-3/.

Also, there is a new webinar recording about the future of Selenium here: http://testautomation.applitools.com/post/144952401467/webinar-recording-selenium-30-the-spec-and.

Happy testing and... make it green, becomes a dream :).

Friday, April 15, 2016

Your First Protractor Test in Visual Studio 2015

Introduction


In this article we'll see how we can create our first project in Visual Studio 2015 that uses Protractor to test an angularJS application.
What is Protractor: "... is an end-to-end test framework for AngularJS applications. Protractor runs tests against your application running in a real browser, interacting with it as a user would."
The official site is this: http://angular.github.io/protractor/#/. 



Why to use Protractor


The main reason for using Protractor is that will recognize specific AngularJS identifiers, like model, repeater, etc.




Another important reason for using it is that when running tests you don't need to wait until the response will return.



Requirements


In order to be able to run Protractor tests we need first to have
- java sdk installed: http://www.oracle.com/technetwork/java/javase/downloads/index.html
- node.js installed: https://nodejs.org/en/download/
- NodeJS Tools for Visual Studio 2015: https://www.visualstudio.com/en-us/features/node-js-vs.aspx


Installation


After node.js was installed on your computer you can use npm to install Protractor globally with:



This will install 2 commands, protractor and webdriver-manager. To verify if protractor was installed run this command in your cmd: protractor --version. Protractor is installed globally under: c:\Users\yourUser\AppData\Roaming\npm\. Webdriver-manager is the tool that will instanciate a Selenium Server. In order ro use it and to start it we need to:





This needs to remain opened while you are running your tests. It will start up the Selenium Server and will output logs. Protractor tests will send requests to this server to control a local browser. 
Below you can see in mode details what Protractor's doing:



Writing your first test


Open Visual Studio 2015 and create a new project of type Blank Node.js Console Application. 



Delete app.js, because you'll don't need it. You'll notice that in your npm references, protractor will be available as a global one.


Protractor needs 2 files to run, a spec.js file that contains the tests and a conf.js file that will tell what specifications will be run and where to talk to Selenium Server (seleniumAddress).
Add the conf.js and spec.js files to your project.


Spec.js should have the structure below, where describe and it represents Jasmine framework syntax. Browser is used by Protractor to navigate in the browser.



If webdriver-manager is already started, now you can run your test in the command line where your conf.js file is by using this command:



A Chrome browser window will be opened. In your cmd you should see the test result.


Using IntelliSense


If you want your jasmine, protractor syntax to be recognized in Visual Studio you need to do additional steps:
- open a cmd and run these commands npm tsd -g 
- then go to the location of your project (in our case c:\temp\Protractor\MyFirstProtractorExample\MyFirstProtractorExample\) and run the following commands 
tds install jasmine
tsd install angular-protractor
tsd install selenium-webdriver
These commands will install the necessary typings for your project


- then you need to add the typing reference to your spec file






More about AngularJS Testing you can find in this book: AngularJS Test-driven Development

Happy testing and... make it green, becomes a dream :).

Monday, April 4, 2016

SpecFlow - Using Hooks in your Tests

Introduction


In a previous article we talked about how we can create tests with Selenium and SpecFlow.This article explains how we can use Hooks to run our tests.


What are Hooks


Hooks = event bindings and can be used to perform additional automation logic on specific events, like, for example, the execution of a scenario. To make an analogy, think about Setup and Teardown attributes from nunit framework.


Types of Hooks



The names are intuitive
- Beforetestrun and aftertestrun represents the code that will be executed before and after all tests
- Beforefeature and afterfeature represents the code that will be executed before and after every feature
- Beforescenario and afterscenarion represents the code that will be executed before and after every scenario inside a feature
- Beforescenarioblock and afterscnearioblock represents the code that will be executed before and after every scenario block
To be more precise, below you can see an example of a scenario with 3 blocks. The test will be executed before and after Given/When/Then blocks

- Beforescenariostep and afterscneariostep represents the code that will be executed before and after every scenario step

Creating Hooks File


After you added the Spec Flow extension to your visual studio project, you are able to create a new item of type Hooks.



A default class is created:



Modify this class and add all hooks you need.

Restrict Hook Execution with Tag Filtering


Another specflow feature is to restrict hook execution based on the tags you set to your scenarios. If you didn't know for a scenario you can add a tab. Based on this you group your tests when running them. In the image below, the scenario tags are @Login and @forgotPassword



The code below from you hook file will be executed for those scenarios tagged with @Login and @forgotPassword (when we are in if)




Want to lean more about BDD? Have a look on this book: BDD in Action: Behavior-driven development for the whole software lifecycle


Happy testing and... make it green, becomes a dream :).


Friday, January 15, 2016

Linking your Selenium Tests to Microsoft Test Manager

Introduction


In this article we will write about how you can link your selenium web driver tests from Visual Studio to Microsoft Test Manager.
Why should we do this? Because with CodedUI you can run your tests only on a IE browser (even there is a plugin that allows you to run coded ui tests on FF/Ch, which is unfortunately not very stable). With selenium, you'll be able to run them much easier on different browsers.

What do you need for this:

- knowledge about Visual Studio Controllers and agents

- knowledge about TFS builds

- knowledge about MTM (Microsoft Test Manager) and how to set an environment

- Have some tools installed: Visual Studio 2013 Online

- know how to work with Selenium WebDriver with C#
- MSTest (not NUnit)to run the tests


Visual Studio Test Controllers and Agent

I'm not going to give you details about this subject because this is a complex one. But, in order to explain you this post, you need to know what MTM environment is. In order to run your automated tests on a specific page, you need to set an environment, which requires a controller that controls one ore more agents. For more details visit this link: https://msdn.microsoft.com/en-us/library/hh546460(v=vs.120).aspx.
Visual studio agent and controllers can be downloaded from here: https://www.microsoft.com/en-us/download/confirmation.aspx?id=40750.
Once you set your controller, you need to add an environment in MTM. To do this open MTM as an admin --> Lab center and create a new environment.
In Type and name, leave the default standard environment and give a name to this new env
In Machines enter the name of the computer where you want to install your agent that will execute the tests and that will be connected to a controller.
In Advanced, select the controller and check Configure environment to run UI tests = Web Client



Verify and restart computer. After restart you'll see a popup with your agent



MTM Build

Another important setting is the build for your automated testing project (with selenium tests).
A build for a MSTest project can be created from Visual Studio. Having your selenium web driver solution opened, go to Team Explorer --> Builds --> New Build Definition.
In Source Settings Add the Repository name:


Build Default -> if you use Visual Studio Online, you can leave it to Hosted Build Controller
Process --> set the path to your .sln solution
Run your build

Adding Environment and Build to MTM Test Plan

Once you have add your agent and build, you need to assign these two, to your test plan in MTM.
Open it, select your test plan, go to Organize and made the settings below.

Create your Selenium Test and Associate it to a Manual Test from MTM

Now you should create your selenium tests. To be much easier, instead new MSTest, create a new CodedUI test. Why, because you'll need (in order to run it from MTM) the CodedUI attribute for a class. Inspect the code below:


This will only open google home page. You can see the DeploymentItems attributes. They are required, in order to deploy chrome and ie drivers on the agent you'll run your tests.
After you created your test, you need to associate it to a dummy MTM test (or to an existing recording in MTM - see this link for more details: http://blogs.infosupport.com/testing-your-web-application-with-selenium-and-mtm-part-2/).
To associate Mstest to MTM test in Visual Studio (with the solution opened), go to TeamExplorer --> Work Items-->made a new query that will return all manual test cases written for this project --> open your manual tc --> go to Associated Automation and select your MSTest


Now you can start running your test from MTM. While the test runs, you'll see this in Agent Popup.

Happy testing and... make it green, becomes a dream :).

Wednesday, December 23, 2015

Some WebDriver Utils for your Visual Studio project

Introduction

In this article we will write about some utils methods that are useful in your selenium webdriver framework
- Visual Studio 2013
- Selenium WebDriver with C#
- Nunit to run the tests
- An existing page object framework


Utils class

In our framework we created Utils.class that contains different methods used in  nunit tests in order to work with mouse events, selection control, string manipulation, etc.

Mouse Events

If you cannot perform wevdriver mouse events by using the usual way, with action class, replace this with 
javascript.




... and with Action class


Work with Alerts, Windows, Frames

Below, you can find some methods used to switch to alert, window, frame











String helpers







Selection controls







Happy testing and... make it green, becomes a dream :).

For every post I'll recommend something to read. The link for today is:  The C# Player's Guide (2nd Edition).

Popular Posts