Monday, February 27, 2017

Selenium WebDriver - How to Identify Web Elements Using Selenium XPath

תוצאת תמונה עבור ‪selenium Xpath‬‏The XML path language (XPath) is a language that we can use for investigating specific nodes of an XML document based on specific search criteria.

Selenium WebDriver supports the XML path language as a strategy to locate elements using flexible XPath queries, this fact is very important, because all the major browsers (Firefox, IE, and chrome) support it.

In Addition: 
  • Not like the CSS strategy, XPath can identify parent element using his chilled element.
  • XPath is the least preferable strategy to locate elements due to a reduce performance when compared to other strategies.
  • A single / slash at the beginning of the XPath, instructs the XPath locator to search for element starting from the root node.
  • A double // slash at the beginning of the XPath, instructs the XPath locator to search the element anywhere. 
For more information about XPath, you can use the following address: 

XPath expressions that we can use to locate elements


Finding elements with absolute path







Firefox.Navigate().GoToUrl("http://www.machtested.com/");             
WebElement = Firefox.FindElement(By.XPath("/html/body/div[3]/div[2]/div[2]/div[2]/div[1]/div[2]/div[2]/div[1]/div/div/ul/li[3]/a "));

Finding elements with relative path

Using the element relative path, we can locate the element directly and without the need to provide the full location in the DOM.

In addition, when using a relative path, there are many elements that may be matched to the search query, therefore it will return the first element found in the DOM.

Example:
Firefox.Navigate().GoToUrl("http://www.machtested.com/");  
WebElement = Firefox.FindElement(By.XPath("//li[3]/a"));

Finding elements based on index

To overcome the "First element returned" issue that we saw in the previous example, we can the element Index that will be used as another filter.

Example:
Firefox.Navigate().GoToUrl("http://www.machtested.com/");  
WebElement = Firefox.FindElement(By.XPath("//li[3]"));

Finding elements using attributes

We can locate elements using their attributes in XPath (Similar to the same option in CSS).

Example:









We will search for the input element (In that case it’s the name field) with the following attributes:
ID attributes:
WebElement = Firefox.FindElement(By.XPath("//input[@id='ContactForm1_contact-form-name']"));

Name attribute:
WebElement = Firefox.FindElement(By.XPath("//input[@name='name']"));

Size attributes:
WebElement = Firefox.FindElement(By.XPath("//input[@size='30']"));

Using Logical operators to filter elements

In some scenarios, you will need to use more than one attribute to locate an element, using logical operators such as 'Or'/ 'AND' will help you to achieve better results in the element filtration process.

Examples:
Case 1 (Or):
WebElement = Firefox.FindElement(By.XPath("//input[@size='30' or @name='name']"));

Case 2 (And) :
WebElement = Firefox.FindElement(By.XPath("//input[@size='30' and @name='name']"));

Locate element regarding the type of the attribute (* Wildcard)

We can use the * wildcard to search based on an attribute value, the important thing is that the search is made regarding the attribute type.

Example:
If we search for the string "Email", XPath will query all elements and their attributes to validate if there is any attribute value that matched to it.

HTML Code:
<input style="width:140px" name="email" type="text">

Code:
WebElement = Firefox.FindElement(By. XPath("//input[@*='email']")); 

Saturday, February 25, 2017

Lesson #14 - Elements search using the FindElements function (C#)

As previously explained, we should work with the FindElements method, only if we need to work with a list of tags or multiple elements.
תמונה קשורה

Code Examples

Example no'1: Locating table values











The following code will examine each row on table and print it to a local file:

StreamWriter sw = new StreamWriter(@"C:\Debugg.txt", true);
WebElement = Firefox.FindElement(By.XPath("/html/body/table/……"));
IList<IWebElement> ListOfElements = WebElement.FindElements(By.TagName("tr"));
foreach (var item in ListOfElements)
{
sw.WriteLine(item.Text);
}

Example no'2: Locating multiple elements using a specific attribute


The following code will search for all the <Input> elements that have the 'name' attribute (Ignoring the attribute value).

IList<IWebElement> ListOfElements = Firefox.FindElements(By.XPath("input[@name]"));

Friday, February 24, 2017

An Introduction to API Testing | David Tzemach

תוצאת תמונה עבור ‪software  API‬‏What is API?

An API (Application Programming Interface) is a set of application code, standards, protocols and procedures that can be used as an interface by external software applications or between different layers of the same application (AKA: “Logic Tier” or “Business Layer”).

When creating an application API, we will determine how other systems will interact, communicate and share data with our system in the best and efficient way.

Motivation to test API

Think about a scenario that you release an API to other programmers with the attention that they will use it as an interface interact with the application, any defect that will affect this basic goal, will resolve an additional development and testing activities (Similar to any other bug found in customer environment) that will affect both the costs and reputation of the company.

Although API’s are usually published for free as an open source code that other developers can use and expand it, there is no way that the market will adopt and use it if it’s not efficient, effective and off course free from any major defects.

What is an API testing?

API testing is a testing approach that is used to validate that APIs and the integration they should provide actually work as defined at the beginning of the project.

The main activity of this testing approach is to validate the API response or output based on varying test conditions, the API output can be a reference to another API, Different types of data, and Pass/Fail status.


What tests should be performed on API’s

  • Test that the API does not have scenarios that he fails to return any response.
  • Test that the API can be integrated with a corresponding system.
  • Test that the API can be integrated with a corresponding API’s.
  • Test the API outcome based on different input condition.
  • Test the how easy is to implement and use the API.
  • Test different performance aspects of the API.
  • Test that the API can process a lot of inputs.
  • Test that the API can handle negative inputs.
  • Test different security aspects of the API. 


What are the types of defects that API testing will help remove?

  • Any Security breach in the API that other programmers can use to attack the system. 
  • Errors and failures that are not handled in a graceful way.
  • Unused code, Duplicate functionality or unused flags.
  • Any functional defect related to the API functions.
  • Performance related defects.
  • Security related defects.


What are the challenges of API testing?

There can be many challenges when testing APIs:

  • The testing is limited to specific functions and there is no view of the full picture.
  • There is a Hugh challenges to test the API output under some systems.
  • There is no User Interface that the tester can use to simplify the tests.
  • Ok, let’s say it, API testing can be complex to some testers.
  • Not like other Black-Box testing methods, in API testing the tester must have a coding knowledge that he will use to execute tests.
  • There is no access to the source code.
  • There is another testing level where the tester needs to verify the exception handling created for specific methods. 


Sunday, February 19, 2017

Lesson #13 -Finding element using the Tag Name attribute

תוצאת תמונה עבור ‪selenium webdriver‬‏Selenium WebDriver provides another strategy to locate web elements using their "Tag Name", in most cases we will use this strategy when we need to find multiple tags in a web page or when working with tables.

In addition,
  • There is no reason to work with this locator when you need a single element.
  • If possible, make sure that the selected TAG is unique.
  • When the element is not found during the code execution, the method returns error type “NoSuchElementException”.
  • The first TAG with this name will be used when executing the code (In a case of duplications).

Code Example

To locate the main title element in my blog, we will now use the "Tag Name" attribute:

<div class="titlewrapper"><h1 class="title"> David Tzemach's Blog </h1></div>


[TestMethod]
public void FindElementByTagName()
{
IWebElement WebElement;
IWebDriver Firefox = new FirefoxDriver();
Firefox.Navigate().GoToUrl("http://www.machtested.com/");
WebElement = Firefox.FindElement(By.TagName("h1"));
}


Lesson #12 - Finding element using the Class Name attribute (C#)

You can use the class name to find attributes in the following way.


Code Example
To locate the contact form user name field, we will now use the class attribute:
<input type="text" value="" size="30" name="name" id="ContactForm1_contact-form-name" class="contact-form-name">

[TestMethod]
public void FindElementByClassName()
{
IWebElement WebElement;
IWebDriver Firefox = new FirefoxDriver();
Firefox.Navigate().GoToUrl("http://www.machtested.com/");
WebElement = Firefox.FindElement(By.ClassName("contact-form-name"));

}

Saturday, February 18, 2017

What is Automation Testing? | David Tzemach

Overview

Automated testing is another layer that we can use besides to the traditional manual testing, as we all know, manual testing is performed by testers that design and execute tests on a system manually and without any use of external tools. 

Automated testing means that engineers (QA/Developers) will use an automation framework/Tool to execute tests that they used to run manually, this is done when each step in the test scenario is scripted including the test data and the expected/actual results of the test.

In my opinion, both manual and automation testing should always be combined during a testing project, the true art is to determine the amount of effort to invest in which one of them based on the project complexity, deadlines, and Risks.

תוצאת תמונה עבור ‪automation testing‬‏

What are the objectives of using automation tools?

The following list will summarize the objectives that we aim to achieve when using automation tools:
  • Increase the return on investment (ROI) in the long-term.
  • Generate a reusable code for future projects.
  • Reduce the number of manual testers.
  • Improve the efficiency of the testing team (we will want to reduce the number of test cases that we run manually).
  • Improve the time to market.
  • Increase the test coverage.

What can we achieve using automation tools?

There are some major goals that we can achieve using automation tools:
  • Make testing more fun and allow the tester to contribute more to the quality effort.
  • Make an efficient test scheduling (Test can run at night via predefined schedule).
  • After the first implementation, we can remove the manual testers from the regression cycles (in Simulate test scenarios that we cannot achieve using manual tests.
  • We will be able to implement an automated “Continues integration” process.
  • Will help the engineering team to achieve an efficient resource utilization.
  • The best scenario, the entire regression cycle will be automated).
  • Run a large number of test cases in a narrow period of time.
  • Reduce the time effort to build the test environments.
  • We will be able to run the tests 24/7.
  • We can create and execute tests to validate application requirements and specifications.
  • We will get a fast feedback about the status of the application (Using automation reports),

What Test Automation is not?

Usually, using automation tools during the testing effort is essential no matter what is the scale of the project, once said, we still need to remember that automation testing will not:
  • Replace the need to plan, Design and write the test plan.
  • Automation is NOT testing! You will always need to add the eye of the human tester.
  • Be easy to maintain after a while. 
  • Pay off on the first testing project, but will remove the need to perform the same tests again.


Why may testing teams reject the implementation of automated tests?

Many companies are still using manual testing without carrying out an automated testing process, let’s review the commonest reasons that may explain why.


Job Security

It’s a simple and logical assumption, in many cases, manual testers that do not have experience in automated tools or coding will reject the idea to use automation because of they afraid that it will make them less relevant in the future.


Application Complexity

In some rare cases, the application being tested manually is just too complex for automated testing.


Costs

Although there are some great free tools that we can use to automate almost everything, in most projects we will buy a dedicated expensive tool, Sometimes, organizations will reject the investment in automation tools due to lack of budget.


Time

Implementing Automated process is a time-consuming task, testing teams will need to investigate what alternatives are available to replace the manual process, learn how to use the selected tool, writing the code and maintain it. 

All these tasks will take time that Sometimes the company cannot afford (Startups and small companies are a great example), therefore they will invest more time in development and continue to test manually until the product will become too big to test manually.

 

Common Types of Automated Testing Tools

Automated testing is relevant to all testing levels and testing types, I created this simple table as a reference to the most known and popular testing tools.

Test  
Automated Tool
Unit Testing
TestNG, NUnit,xUnit…
Security Testing
WireShark, WebInspect, fiddler….
Penetration testing
CORE impact, Metasploit, Nessus, Retina,Sqlmap,Sqlninja,beEF,Hydra, Nagios,Nmap…..
Performance Testing
JMeter, LoadRunner, WebLoad, NeoLoad,Qtest,Loadster,Wapt….
Regression Testing
TestCafe,QTP,vTest,Winrunner,TestComplete …
Web testing
SoapUI,Ranorex, Selenium, Browsershots, IE Tab, BrowserCam,Watir…
Mobile Testing
Frank (iOS), iOS UI Automation (iOS), Robotium (Android),Appium (Android/iOS)…
Cloud Testing
SaltStack,Fabric, Chef, Puppet, Juju…

Friday, February 17, 2017

Lesson #11 - Selenium WebDriver - Finding element using the Link/Partial Link text attribute (C#)

We can search elements using their link attribute, we can use either the full link of the element or only part of it.

In addition,
  • The first Link with this name will be used when executing the code (In case of duplications).
  • When the element is not found during the code execution, the method returns error type “NoSuchElementException”.


Code Example





To locate the contact form user name field, we will now use the "link Text" attribute:
<a href="http://www.machtested.com/p/blog-page_11.html">Quality Assurance</a>

[TestMethod]
public void FindElementByLinkText()
{
IWebElement WebElement;
IWebDriver Firefox = new FirefoxDriver();
Firefox.Navigate().GoToUrl("http://www.machtested.com/");
WebElement = Firefox.FindElement(By.LinkText("Quality Assurance"));
}

[TestMethod]
public void FindElementByPartialLinkText()
{
IWebElement WebElement;
IWebDriver Firefox = new FirefoxDriver();
Firefox.Navigate().GoToUrl("http://www.machtested.com/");
WebElement = Firefox.FindElement(By.PartialLinkText("Quality"));
}

Lesson #10 - Selenium WebDriver - Finding element using the Name attribute (C#)

Finding element using the Name attribute

תמונה קשורהAlthough it's sims very logical to find am element by his name, there are few major limitations that you need to know:

·      The name attribute may not be unique on a page (the same name can be assigned to multiple elements).
·      If you use this attribute and it's assigned to multiple elements, the first element on the page with this name will be returned by the API.
Code Example
To locate the contact form user name field, we will now use the name attribute:

<input type="text" value="" size="30" name="name" id="ContactForm1_contact-form-name" class="contact-form-name">

[TestMethod]
public void FindElementByName()
{
IWebElement WebElement;
IWebDriver Firefox = new FirefoxDriver();
Firefox.Navigate().GoToUrl("http://www.machtested.com/");
WebElement = Firefox.FindElement(By.Name("name"));
}

Saturday, February 4, 2017

Negative testing Checklist | David Tzemach

The Negative testing approach is relevant to many areas of any given software; this list will review the main possible areas that are suitable to this testing approach.

תוצאת תמונה עבור ‪defect free software does not exist‬‏

Input Fields

Every object in a software is designed based on the software preliminary demands that are located in the software requirements specification(SRS) document. Among this different objects, we can find the “Input” fields, in most cases that SRS doc will specify a few mandatory specifications that the field should support, these specific requirements are crucial to the test team to understand how to design both the “Negative” and “Positive” test scenarios.

The field Length


The specification doc will determine the “Minimum “and “Maximum” length of the input field (What is the Min/Mac string that the user can enter), for example, an input field that receives a Minimum string length of 2 chars and Maximum length of 10.  The basic test cases are: 

  • Insert number of chars within the boundary values ‘5’ (Positive scenario).
  • Insert number of chars that is Lower than the MIN value ‘1’ (Negative scenario).
  • Insert number of chars that is Higher than the MAX value ‘11’ (Negative scenario).

Field data type

The specification doc will determine the data types supported by the input field. For example:
  • A field that can receive all types of chars.
  • A field that can receive only numbers.
  • Alphabetic field that should not allow numeric values.

For example, let’s assume that we have a numeric field, the basic test cases are:
  • Use input string that contains numbers (Positive).
  • Use  input string that contains Alphabetic chars (Negative).
  • Use input string that contains special characters (Negative).

Data Field Boundaries

The specification doc will determine the boundary values of each field, for example, an input field that set with Min (2) and Max (5) string length, the basic test cases are:
  • Insert input string that within the boundary values ‘4’ (Positive).
  • Insert input string of the MAX value ‘5’(Negative).
  • Insert input string of the MIN value ‘2’ (Negative).

Date Fields

A date field is used to specify a date value, it is important that we validate the basic rules for such fields, the basic test cases are:
  • Validate that user uses only numbers.
  • Validate that user uses the correct date format.
  • Validate dates with/without leap years.

Web Session 

Almost any web application will use the browser session to track and monitor the user while he using the application (Settings, validations and more). To be able to do so, the user should be logged-in and authenticate against the backend server.  

This authentication process will allow the test team to create test cases that simulate the use of WebPages without first logging in and authenticate (from the application perspective, this case is Unexpected).

During this test cases, we will need to validate how the application can handle such scenarios and to examine how to enforce the authentication process prior to allowing the user to use the service. 

Performance

Testing the functional behavior of the application is crucial, but we must also combine it with performance testing that will help us to query about the application limitations in ways it was not intended to be used.

Performance test techniques
  • Stress
  • Failover
  • Load
  • Pike


Example:
In stress testing we will test the application with data exceeding the application upper limitations, in that case we will probably cause errors or crushes, this is now the tester time to understand the root cause of the problem and how the application recovers.

For more reading about performance tests and its importance:

Object Upload

Another great example that will demonstrate the importance of negative testing is the “Upload” object that is very common in many applications, using the functionality of this object, the user can upload data set from a specific source (Excel, CSV, DB etc.).

Let’s assume that we have this object, that allow the user to select a CSV file as a source, once uploaded the application will use the data set to create a report, from the negative perspective, we can design an infant range of test cases, Examples:  

  • Upload file without the relevant permissions.
  • Delete the source file after it was uploaded.
  • Upload CSV file with an incorrect format.
  • Upload file that does not exists anymore.
  • File Upload from a remote location.
  • Upload files without extension
  • Upload empty files.
  • Upload CSV file that was created from other file type (Simply manually change any other file type into csv).

Connectivity and Availability

Negative testing are also used to test the application connectivity and availability, using this testing method, we will have the power to make a real difference in the application stability and overall quality.

Let’s assume that you have a small application that has three main components that interacts one with each other:

  • Database
  • User interface
  • Application service

We will use Negative testing to attack the interfaces between these components, let’s review the basic examples:

  • Try to save changes in GUI when the database is down.
  • Try to use the application functionality when the service is down.
  • Shut down the DB connection while saving data.
  • Shut down the application service while it’s online.
  • Simulate End-To-End cases on a low bandwidth environment.
  • Save data to database without the appropriate permissions. 


My Presentations