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

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.

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.

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).


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.

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.

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">

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)

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. 

My Presentations