by admin | Jun 22, 2016 | 2016, Fixed |
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;
}
}
by admin | Aug 28, 2016 | 2016, Fixed |
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
by admin | Aug 24, 2016 | 2016, Fixed |
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<WebElement> elements=driver.findElements( By.xpath("//input[@type='checkbox']"));
elements.stream()
.filter(element->Pattern.compile("check_(\d+)_box").matcher(element.getAttribute("id")).matches())
.forEach(element->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?
by admin | Jun 29, 2016 | 2016, Fixed |
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"))
)
);
by admin | Jul 11, 2016 | 2016 |
We would like to share Aslak Hellesøy’s (the creator of Cucumber) reply in Quora for “Why is the Cucumber tool for BDD named as such”. Interesting answer worth reading.
This is going to be a little long – I’ll take the opportunity to explain a little more of the history of some BDD tools.
Around 2005-2007 I was involved in the RSpec open source project – the first popular BDD framework for Ruby.
In 2007 Dan North (who invented BDD) had just donated his rbehave tool to the RSpec project where it was renamed to the RSpec Story Runner. Dan is a starter.
David Chelimsky who was the lead of the RSpec project refactored the story runner so it could read stories from plain text instead of a Ruby DSL – using a simple regex based parser. This was now the first tool in the world to allow executable specifications to be written in plain text using Given/When/Then.
I thought the RSpec Story Runner was a fantastic idea and I started to devote my energy towards improving it. One of the first things I did was to rewrite the parser using Treetop. About a year later, in the spring of 2008 I had a lot of ideas for improvements.
I wanted users to have better error messages. I wanted to make it easier to use by printing step definition snippets and report results in colours. I wanted non-English speakers to use the tool, so I wanted to translate Given/When/Then to other languages. And a lot more.
Implementing these changes was very hard to accomplish without making deep changes to RSpec itself, which RSpec Story Runner depended upon. The two projects had very different goals – RSpec was primarily for programmers, while RSpec Story Runner aspired to be a tool for the whole team, including non-technical stakeholders.
So on the 8th of April 2008 I made my first commit in a codebase that I wanted to become a better, standalone rewrite of the RSpec Story Runner. I temporarily named it Stories for lack of a better name.
I knew this thing could be big – I just knew it! But that would never happen with a boring name like Stories. Can you imagine using a tool called Stories?
So after three days of hacking on my new baby I was on a 3 hour bus ride from Oslo towards Risør with my fiancee. She couldn’t care less about programming, but I always admired her sense of aesthetics and good taste, so I asked her:
Patty, I need a name for this new tool I just started hacking on. I want it to have a catchy, non-geeky sounding name.
She paused for a few seconds, then said: Cucumber!
And I thought: Cucumber? Really? Well, it’s a lot better than Stories – so I’ll go with that for now. I’ll rename it again when I come up with something better.
8 years later I still haven’t come up with a better name. And now there are hundreds of thousands of people using Cucumber every day, from small tech startups to fortune 500 companies.
Crazy
Source Quora: https://www.quora.com/Why-is-the-Cucumber-tool-for-BDD-named-as-such