Book demo
Start trial
Book demo
Start trial

The LEAP

Automation insights and productivity tips from LEAPWORK.

All Posts

Codeless Web Automation Case: Booking a Hotel Room

Here's an example of how to automate a web application with LEAPWORK.

The more people we talk to from small shops to global companies in finance and tech, the more confident we are that our vision for LEAPWORK is correct: Testers are not programmers. But up until now, testers have been forced into programming with little or no training in order to meet increasing demands for automation because the available tools simply require it.

We're changing that with LEAPWORK.

And to prove it, here's an example of how LEAPWORK stacks up against the popular web testing tool Selenium. We're looking at a list of places to stay in Copenhagen on Hotels.com and we want to:

  • Find a room that costs less than 1000 DKK per night (the local currency)
  • It must be closer than 1 mile to the center of the city
  • When found, click the price listed to view the room

Hotels.com screenshot being automatically tested with LEAPWORKHere's how to do that in LEAPWORK, using our unique building blocks that can get numbers with filters, format rules and scroll-to-find built right in:

Test case that finds a cheap hotel using number recognition building blocks in LEAPWORK

That's the whole test case. And as with other LEAPWORK cases, it's fairly simple to understand what it does just by looking at it:

  • We get all price numbers that are less than 1000 DKK from a certain area of the screen
  • For each number, we offset the position found and use that to get the distance to the city center, which must be less than 1,0
  • If both the price and distance numbers are good, the price is clicked and the case is passed
  • If not, the loop just continues, scrolling down a maximum of 10 times
  • The green wires show the flow between blocks, while the blue wires pass values around

This is a great example of how powerful the visual nature of LEAPWORK can be -- it took less than 5 minutes to put this automation case together.

The Selenium version, on the other hand, was neither easy nor quick to make, clocking in at 1 hour and 15 minutes because of some complex XPath logic:

using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading; >namespace TestProject1
{
[TestClass]
public class HotelsTest1
{
[TestMethod]
public void FindHotelTest()
{
// Setup omitted for brevity

 

try
{
int count 0;
while (count < 10) {
// Find a hotel that costs less than 800 DKK per night.
var priceElementsl = driver.FindElements(By.XPath("//div[@c1ass='price']/a/span/ins"));
var priceE1ements2 = driver.FindElements(By.XPath("//div[@c1ass='price']/a/b"));
var foundElements1 = priceElementsl.Where(p => Convert.ToDecimal(p.Text.Replace("DKK", "")) < 710);
var foundElements2 = priceElements2.Where(p => Convert.ToDecimal(p.Text.Replace("DKK", "")) < 710);
var allFoundElements foundElements1.Union(foundElements2);
if (allFoundElements != null && allFoundElements.Count() > 0)
{
foreach (var foundElement in allFoundElements)
{
// Closer than 1 mile to the city center.
var hotelElement foundElement.FindElement(By.XPath("./ancestor::div[@class='hotel-wrap']"));
var distElement hotelElement.FindElement(By.XPath(".//div[@class='location-info resp-module']/ul/li"));
var distance = Convert.ToDecimal(distElement.Text.Substring(0, distElement.Text.IndexOf("km")));
Debug.WriteLine("Found right price element '{0}', now checking distance: {1}", foundElement.Text, distance);
if (distance < 1)
{
// Click the price and pass.
foundElement.Click();
Thread.Sleep(2000);
return;
}
}
}

 

IJavaScriptExecutor jse = (IJavaScriptExecutor)driver;
jse.ExecuteScript("window.scrollBy(0,800)", "");
Thread.Sleep(2000);

 

count++;
}

 

Assert.Fail();
}
catch (Exception ex)
{
Debug.WriteLine("An error occurred:" + ex.ToString());
}
finally
{
driver.Quit();
}
}
}
}


Dig deeper into web automation with the LEAPWORK guide on everything you need to know to automate web-based tests and processes.
The LEAPWORK Guide to Web Automation

Claus Topholt
Claus Topholt
CTO and co-founder of LEAPWORK.

Related Posts

Comparison: Selenium IDE vs. LEAPWORK

Selenium IDE is a great open source tool for HTML-savvy users who want record and playback automation of simple web applications, but isn’t suitable for enterprises and has very limited functionality. This post compares Selenium IDE with LEAPWORK enterprise web automation.

Comparison: LEAPWORK vs. Selenium Web Automation

Selenium is a great tool for professional programmers who want to automate web applications, but for users who don’t (want to) write code, there are better options. This post compares code-based Selenium with LEAPWORK web automation. Side-by-side video comparison included.

Test Automation Frameworks: Why They Fail

Test automation frameworks are basically recipes for how to build automated test cases. They include guidelines for testers on how they should do their job. The problem is, these frameworks don’t always work, as they tend to complicate test automation more than necessary.