Select Page

Category Selected: 2016

53 results Found


People also read

API Testing

Postman API Automation Testing Tutorial

Automation Testing

Top 10 AI Automation Testing Tools

Automation Testing

Talk to our Experts

Amazing clients who
trust us


poloatto
ABB
polaris
ooredo
stryker
mobility

Useful XPath Expressions

For Selenium beginners, the below listed XPath examples are really helpful to write a relative XPath instead of messing up with an absolute one.

1) Select First & Last Node
  • Selecting first hyper link in a page_xpath=/descendant::a[1]
  • Selecting first link using Position method_xpath=/descendant::a[position()=1]
  • Selecting last link_xpath=/descendant::a[last()]
  • Selecting first link which has innerText as ‘English’:xpath=/descendant::a[text()=’English’][1]
  • Selecting first input tag which has ‘class’ attribute_xpath=/descendant::input[@class][1]
2) Selecting a node using multiple condition
  • Selects input tag using ‘type’ and ‘class’ attributes value_xpath=//input[@type=’text’ and @class=’gbqfif’]
  • Selects a button which has name and class attributes: xpath=//button[@name and @class]
3) Getting parent node from child node
  • Gets the input tag’s parent node using ‘..’ : xpath= //input[@name=’q’]/..
4) Selecting parent node from child node
  • Selects the ‘DIV’ which is having ‘INPUT’ tag: xpath=//div[input]
White Framework Cheat Sheet

White Framework Cheat Sheet

Everyone is aware of automating rich client applications using White framework. As a software testing service provider, sharing our experience and knowledge is one of the success factors for Codoid. In this blog article, we would like to share useful White framework methods with examples.

Launch an Application
Application application = Application.Launch("C:\Windows\System32\calc.exe");
  
Attaching an existing Application
//Attach by process id
Application application=Application.Attach(10628);

//Attach by process name
 Application application = Application.Attach("calc");
  
Attach or Launch
//Attaches to the process, if it is running or launches a new process
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "calc.exe";
Application application = Application.AttachOrLaunch(startInfo);
  
Get Windows
//Get Window by title
 Window window =application.GetWindow("Calculator");

//Search a window with criteria
Window window = application.GetWindow(SearchCriteria.ByText("Testing services Companies"), TestStack.White.Factory.InitializeOption.NoCache);

//Returns a list of all main windows in belonging to an application. It doesn't return modal windows.
List<Window> windows = application.GetWindows(); 
  
Speed up window search performance

You can store window’s position in White-framework cache xml file by providing identification string in GetWindow method. For the very first run, it will store the window position. And for the subsequent executions, it accesses the cache xml and identifies your window quickly. For more details, refer the following link: Speed up performance by Position based search

Application application = Application.Attach("notepad");

Window window =application.GetWindow("Codoid-A Test Automation company - Notepad", TestStack.White.Factory.InitializeOption.NoCache.AndIdentifiedBy("Notepad"));

application.ApplicationSession.Save();
  
Desktop Windows
//Returns a list of all main windows on the desktop. It doesn't return modal windows.
List<Window> windows = Desktop.Instance.Windows();
  
Get Modal windows
//Get list of all the modal windows belong to the window.
List<Window> modalWindows = mainWindow.ModalWindows();

//Get modal window with title
Window childWindow = mainWindow.ModalWindow("child");
  
Get Tool tip
string message = window.ToolTip;
  
Take Screenshot
//Takes a screenshot of the entire desktop, and saves it to disk
Desktop.TakeScreenshot("C:\white-framework.png", System.Drawing.Imaging.ImageFormat.Png);

//Captures a screenshot of the entire desktop, and returns the bitmap
Bitmap bitmap = Desktop.CaptureScreenshot();
  
Button
//Find
 Button button=window.Get<Button>(SearchCriteria.ByText("Calculate"));

//Click
button.Click();

//Double Click
button.DoubleClick();

//Right Click
button.RightClick();
button.RightClickAt(new Point(5, 5));

//Is Enabled
bool isEnabledButton=button.Enabled;

//Take screenshot
Bitmap bitmap = button.VisibleImage;
bitmap.Save("C:\button.png", System.Drawing.Imaging.ImageFormat.Png);
  
ComboBox
ComboBox combobox=window.Get<ComboBox>(SearchCriteria.ByAutomationId("261"));

//Select by index
combobox.Select(1);

//Select by text
combobox.Select("Purchase price");
  
Radiobutton
RadioButton radioButton = window.Get<RadioButton>(SearchCriteria.ByAutomationId("322"));

//Select
radioButton.Select();

//Is selected
bool isSelected = radioButton.IsSelected;
  
Textbox
SearchCriteria searchCriteria = SearchCriteria.ByClassName("TextBox").AndIndex(1);

TextBox textBox = window.Get<TextBox>(searchCriteria);

//Clear and enter text. Use BulkText to set value in textbox for better performance.
textBox.BulkText = "QA Services";

//Click center of text box
textBox.ClickAtCenter();
  
Mouse
 Mouse mouse = Mouse.Instance;

//Click
mouse.Click();

//Click with Point
mouse.Click(textBox.ClickablePoint);

//Right Click
mouse.RightClick(textBox.ClickablePoint);

//Double Click
mouse.DoubleClick(textBox.ClickablePoint);

//Get cursor location
System.Windows.Point location = mouse.Location;
  
Checkbox
CheckBox checkbox = window.Get<CheckBox>(SearchCriteria.ByAutomationId("3213482"));

//Check
checkbox.Select();

//Uncheck
checkbox.UnSelect();

//Is checked
bool isChecked=checkbox.Checked;
  
Menubar
//Menu bar
MenuBar menubar = window.MenuBar;

//Selecting menu items
menubar.MenuItem("Tools", "Change language", "Polski (Polish)").Click();

//Searching and selecting menu items
menubar.MenuItemBy(SearchCriteria.ByText("Tools"), SearchCriteria.ByText("Change language")).Click();
  
Listbox
//Check an item
listBox.Check("QA Consultants");

//Uncheck an item
listBox.UnCheck("Quality Assurance");

//Get all the items
ListItems items = listBox.Items;

//Select an item
listBox.Select("Testing and QA Services");

//Get selected item
ListItem listItem = listBox.SelectedItem;
  
Tree
//Select a node
tree.Node("Codoid", "Services").Select();

//Expand a node
tree.Node("Codoid", "Products").Expand();

//Collapse node
tree.Node("Codoid", "Automation Testing").Collapse();
  
Wait Till using Delegate

Using the below technique, you can make your script to wait until a certain condition matches.


    class Program
    {
        public static TextBox textbox = null;

        static void Main(string[] args)
        {
            
            Application application = Application.Attach("calc");

            Window window = application.GetWindow("Calculator");

            textbox = window.Get<TextBox>(SearchCriteria.ByAutomationId("226"));


            //Waits until the textbox value becomes "123". isTextMatch method user defined method for this condition.
            window.WaitTill(new WaitTillDelegate(isTextMatched));

        }

        static bool isTextMatched()
        {
            bool isMatched = false;

            if (textbox.Text.Equals("123")) { isMatched = true; }

            return isMatched;
        }
    }
  
BDD Framework List

BDD Framework List

There are various frameworks available for Behavior-Driven Development (BDD). As an automation testing services company, we have used Cucumber, Behave, and Specflow for test automation projects.

However, we have found and listed 25 BDD frameworks
which are popular among experts.

Cucumber

Cucumber is a software tool that computer programmers use for testing other software. It runs automated acceptance tests written in a behavior-driven development (BDD) style. Cucumber is written in the Ruby programming language. Cucumber projects are available for other platforms beyond Ruby.

Link: https://cucumber.io/

Serenity BDD

Serenity BDD helps you write better, more effective automated acceptance tests, and use these acceptance tests to produce world-class test reports and living documentation

Link: Serenity BDD

SpecFlow

SpecFlow acceptance tests follow the BDD paradigm: define specifications using examples understandable to business users as well as developers and testers. SpecFlow integrates with Visual Studio, but can be also used from the command line.

Link: http://www.specflow.org/

Jasmine

Jasmine is a behavior-driven development framework for testing JavaScript code. It does not depend on any other JavaScript frameworks. It does not require a DOM. And it has a clean, obvious syntax so that you can easily write tests.

Link: http://jasmine.github.io/2.0/introduction.html

GivWenZen

GivWenZen allows a user to use the BDD Given When Then vocabulary and plain text sentences to help a team get the words right and create a ubiquitous language to describe and test a business domain.

Link: https://github.com/weswilliams/GivWenZen

easyb

easyb is a behavior driven development framework for the Java platform. By using a specification based Domain Specific Language, easyb aims to enable executable, yet readable documentation.

Link: http://easyb.org/

Concordion

Concordion is an open-source tool for automating Specification by Example. It’s used by product teams all over the world to help them deliver great software.

Link: http://concordion.org/

cola-tests

COLA Tests are different from all other BDD framework as it allows for developers to keep using any JUnit Runner without having to do any complex configuration or setup.

Link: https://github.com/bmsantos/cola-tests

Behat

Behat is an open source Behavior Driven Development framework for PHP 5.3+. What’s behavior driven development, you ask? It’s a way to develop software through a constant communication with stakeholders in form of examples; examples of how this software should help them, and you, to achieve your goals.

Link: http://docs.behat.org/en/v3.0/

Squish

Squish’s support for BDD is unique because it tightly combines and integrates the BDD approach and GUI test automation.

Link: https://www.froglogic.com/squish/gui-testing/features/index.php?id=bdd.html

Jdave

JDave is a BDD framework for Java. It is inspired by rspec and integrates JMock 2 as mocking framework and Hamcrest as matching library. It uses JUnit adapter to launch JDave specifications.

Link: https://github.com/jdave/Jdave

behave

behave is behaviour-driven development and uses tests written in a natural language style, backed up by Python code.

Link: https://pypi.org/project/behave/

Lettuce

Lettuce is a very simple BDD tool based on the Cucumber, which currently has many more features than Lettuce.
Lettuce aims the most common tasks on BDD and it focus specially on those that make BDD so fun 🙂

Link: http://lettuce.it/

Frank

Frank allows you to write structured text test/acceptance tests/requirements (using Cucumber) and have them execute against your iOS application.

Link: http://www.testingwithfrank.com/

Codeception

All Codeception tests are written in a descriptive manner. Just by looking at the test body you can get a clear understanding of what is being tested and how it is performed. Even complex tests with many assertions are written in a simple PHP DSL.

Link: http://codeception.com/docs/07-BDD

Chakram

Chakram is a REST API testing framework offering a BDD testing style and fully exploiting promises.

Link: http://dareid.github.io/chakram/

Nbehave

NBehave is a framework for behaviour-driven development (BDD). BDD is an evolution of test-driven development (TDD) and acceptance-test driven design, and it is intended to make these practices more accessible and intuitive to newcomers and experts alike.

Link: https://github.com/nbehave/NBehave/wiki/Getting%20Started

Jbehave

JBehave is a framework for Behaviour-Driven Development (BDD). BDD is an evolution of test-driven development (TDD) and acceptance-test driven design, and is intended to make these practices more accessible and intuitive to newcomers and experts alike. It shifts the vocabulary from being test-based to behaviour-based, and positions itself as a design philosophy.

Link: http://jbehave.org/

minitest

minitest provides a complete suite of testing facilities supporting TDD, BDD, mocking, and benchmarking.

Link: https://github.com/seattlerb/minitest

Hiptest

Hiptest, a realtime test management platform that supports behaviour driven development and seamlessly blends in continuous delivery processes.

Link: https://github.com/hiptest

Gauge

Gauge is an open source test automation tool that is completely hackable. Written in golang, Gauge lets you write tests in plain-speak and refactor fearlessly.

Link: https://github.com/getgauge/

LightBDD

Lightweight Behavior Driven Development test framework.

Link: https://github.com/Suremaker/LightBDD

Specter

Specter enables behavior driven development (BDD) by allowing developers to write executable specifications for their objects, before actually implementing them.

Link: http://specter.sourceforge.net/

SubSpec

SubSpec xUnit BDD Framework.

Link: https://github.com/topics/subspecs

System.Spec

System.Spec is testing tool for the C# programming language.

Link: https://github.com/alexfalkowski/System.Spec

Selenium WebDriver and Java 8

Selenium WebDriver and Java 8

From Selenium 3.0, minimum Java version is 8. In this blog article, we would like to show you how to use Java 8 features like Lambda expression and Collections Stream to simplify Selenium WebDriver snippets.

Let’s start with Lambda expression.

Java lambda expressions are Java’s first step into functional programming. A Java lambda expression is thus a function which can be created without belonging to any class. A lambda expression can be passed around as if it was an object and executed on demand.

Source: Tutorials Jenkov

Let’s say you want to print all the elements from an array list without lambda expression; then you will come up with the below snippet.

List list=new ArrayList();

list.add("Selenium");
list.add("UFT");
list.add("Appium");

for(String item:list){
  System.out.println(item);
}
  

The same logic, we can implement a lot easier with lambda expression in Java 8.

list.forEach(item -> System.out.println(item));
  
Collections Stream

Collections Stream is a new feature in Java 8. A stream represents a sequence of elements and supports different kind of operations from a collection.

Let’s say you want to check whether an option is available or not in a drop-down list.

Select select=new Select(driver.findElement(By.id("drp1")));

//Validating drop-down option without For Loop
select.getOptions().stream().anyMatch(item->item.getText().equals("Option1"))
  
Filtering WebElements using Regular Expression
driver.get("file:///C:/sample.html");

List&lt;WebElement&gt; elements=driver.findElements( By.xpath("//input[@type='checkbox']"));

elements.stream()
     .filter(element-&gt;Pattern.compile("check_(\d+)_box").matcher(element.getAttribute("id")).matches())
     .forEach(element-&gt;element.click());  
Getting a visible WebElement from WebElement List
driver.findElements(By.xpath("//input"))
                    .stream()
                    .filter(elemnt -> elemnt.isDisplayed())
                    .findFirst()
                    .get()
                    .sendKeys("codoid-testing company");
  

Very Simple, isn’t it?

Coding Style Guides

In this article, we would like to share style guide for various programming languages. Writing automated test scripts without coding style or following different coding styles in a team should be avoided.

Be consistent with your coding style when a team is contributing into a large codebase.

Ruby

http://airbnb.io/projects/ruby/

C#

https://msdn.microsoft.com/en-us/library/ff926074.aspx
https://www.idesign.net/

Javascript

http://airbnb.io/projects/javascript/

Java

https://google.github.io/styleguide/javaguide.html
http://geosoft.no/development/javastyle.html

A consistent coding style produces understandable and adoptable code base.

Selenium ExpectedConditions With Logical Operators

Selenium ExpectedConditions With Logical Operators

How to check or wait until multiple web elements are visible in one webdriver ExpectedCondition? Or how to wait until at least one element is clickable in a group of web elements?

Selenium WebDriver ExpectedCondition supports logical operators which has answers for the above questions and it also helps to create robust automation test scripts. Let’s see ExpectedConditions’ logical operators with examples.

AND Operator

//Wait until both the elements are visible
wait.until(
              ExpectedConditions.and(
                   ExpectedConditions.visibilityOfAllElementsLocatedBy(By.name("Services")),
                   ExpectedConditions.visibilityOfAllElementsLocatedBy(By.name("Products"))
              )
          );
  

OR Operator

//Wait until at least anyone condition returns true
wait.until(
              ExpectedConditions.or(
                   ExpectedConditions.visibilityOfAllElementsLocatedBy(By.name("Services")),
                   ExpectedConditions.visibilityOfAllElementsLocatedBy(By.name("Products"))
                   ExpectedConditions.visibilityOfAllElementsLocatedBy(By.name("Contact Us"))
              )
          );