Filed under Selenium WebDriver, Test Automation, UI Testing.

Today we are announcing our new live online training session “The Ultimate Selenium WebDriver Testing & Hands-on Guide” which will take place on Saturday, 10th December 2016 – 10:00 UTC Time.

This Revolutionary New Selenium WebDriver training session has a length of 5 hours and is going to be presented in english.

“The Ultimate Selenium WebDriver Testing & Hands-on Guide” is a step-by-step online guide anyone can use to start running automated user interface tests immediately, using proven strategies we’ve used ourselves.
“The Ultimate Selenium WebDriver Testing & Hands-on Guide” is not so much a tutorial as it is a hands-on guide and an interactive session that will handhold you all the way to understanding software architecture, what should / should not be tested and where you should start.

By the time you finish this guide, you will not only have a dozen ideas about different testing strategies to build your own custom automated testing framework, but you’ll know exactly what it takes to implement each one of them and how to use Selenium WebDriver to achieve this goal.

The price of £100 per this live session is a bargain comparing to how much other tutorials cost, and the amount of information you’ll get after this will actually be tremendous. Be one of the few that will know the most important testing tips and tricks which will make you look like a testing guru.

 

This training is brought to you by LoadFocus.com – Cloud Testing Platform.

Filed under Selenium WebDriver, Test Automation, UI Testing.

Here are details related to using waits with Selenium WebDriver in Java. According to the Selenium documentation, at the moment, there are two different type of waits: explicit and implicit.

After you understand how to locate elements with Selenium WebDriver, you have to focus on waiting for elements to appear, be visible, be clickable.

Waiting is an automated step, elapse a certain amount of time, before execution can continue. Choose to use Explicit Waits or Implicit Waits. As a side note, you should not mix implicit and explicit waits.

Implicit Waits in Selenium WebDriver

An implicit wait tells WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available.

The implicit wait is set for the life of the WebDriver object instance.

WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

//use a URL that delays loading elements
driver.get("http://www.example.com/");
WebElement myDynamicElement = driver.findElement(By.id("myDynamicElement"));

You can set the implicit wait when you first instantiate the WebDriver:

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

This specifies the amount of time the driver should wait when searching for an element if it is not immediately present.

Explicit Waits in Selenium WebDriver

An explicit wait represents defined code for certain conditions or behaviours to occur/happen before continued to the next step.

Not a good practice is to add an exact time wait which usually is done by the Thread.sleep() method.

Or you can create a method in order to pass seconds for the explicit wait, but again this is not a best practice:

public void waitSeconds(int seconds){
	try {
		Thread.sleep(seconds * 1000);
	} catch (InterruptedException e) {
		e.printStackTrace();
	}
}

Selenium WebDriver provides some out of the shelf methods that will help you write code that will wait only as long as required.

WebDriverWait in combination with ExpectedCondition is better than what an ExplicitWait can be achieved:

WebDriver driver = new FirefoxDriver();
driver.get("http://somedomain/url_that_delays_loading");
WebElement myDynamicElement = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.id("myDynamicElement")));

This waits up to 10 seconds before throwing a TimeoutException or if it finds the element will return it in 0 – 10 seconds.

Or you can use a generic method in order to wait for elements to be present or visible:

public void waitForElement(int seconds, String waitConditionLocator){
	WebDriverWait wait = new WebDriverWait(driver, seconds);
	wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(waitConditionLocator)));
}

or

public static boolean isElementPresent(By by, WebDriver driver) {
	boolean present;
	try{
		driver.findElement(by);
		present = true;
	}catch (NoSuchElementException e){
		present = false;
	}
	return present;
}

or

there’s an alternative way by checking the count using FindElements which won’t throw an exception:

if( driver.FindElements(By.CssSelector(exportCssSelector)).Count‌() > 0) {//element exists}

WebDriverWait by default calls the ExpectedCondition every 0.5 seconds until it returns successfully. A successful return value for the ExpectedCondition function type is a Boolean value of true, or a non-null object.

Expected Conditions

 

There are some common conditions that are frequently encountered when automating web browsers. Listed below are a few examples for the usage of such conditions. The Java, C#, and Python bindings include convenience methods so you don’t have to code an ExpectedCondition class yourself or create your own utility package for them.
Element is Clickable – it is Displayed and Enabled.

WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("idOfElementToBeClicked")));

The ExpectedConditions package (Java) (Python) (.NET) contains a set of predefined conditions to use with WebDriverWait.


 

LoadFocus.com is a cloud testing platform, use Automated Website Testing Service to build functional tests and automate regression manual tests of your website, more details.

Filed under Selenium WebDriver.

Enroll Now for the new Online Course: How to Find XPath for Web Elements in Chrome and Firefox Browsers.

 

The only reliable way of using XPath in Selenium WebDriver for text with apostrophes (single quotes) is to use double quotes for the expression of the XPath. In order to find how to use XPath to locate WebElements in Chrome browser you can check our previous article.

For example, for the code below:

driver.findElement(By.xpath("//*[@text='" + text + "']"))

you need to change to:

driver.findElement(By.xpath("//*[@text=\"" + text + "\"]"))

This way, it will not matter if your text contains apostrophes or not, and you’ll be able to select web elements by text that contains apostrophes (single quotes).

For example, if the text you want to use to select an element is: We’ll , here is how you can find all web elements that match you apostrophe (single quote) text with Selenium WebDriver.

driver.findElements(By.xpath("//input[contains(@text,\"We'll\"]"));


LoadFocus.com is a cloud testing platform, use Automated Website Testing Service to build functional tests and automate regression manual tests of your website, more details.

Filed under Selenium WebDriver, Test Automation, UI Testing.

Here is how you can find all the Links on a Webpage with Selenium WebDriver in Java.

All you need to do is to create a list of all WebElements, and then iterate thorough the list of links to print the link and the text of the link:

List allLinks = driver.findElements(By.tagName("a"));

System.out.println("All links found on web page are: " + allLinks.size() + " links");

for (WebElement link : allLinks) {

//print the links i.e. http://example.com or https://www.example.com
System.out.println(link.getAttribute("href"));

//print the links text
System.out.println(link.getText());
}

To get the link you can call the “getAttribute” method on the link WebElement passing “href” as its argument which will print the links as i.e. http://example.com or https://www.example.com

Use our older post in order to understand how you can find WebElements on a webpage with Selenium WebDriver.

In order to click on each link element and the go back you can use the following WebDriver code:

for (WebElement link : allLinks) {
   link.click();
   driver.navigate().back();
}

LoadFocus.com is a cloud testing platform:

Filed under Load Testing.

Reasons for 500 Internal Server Errors when doing GET or POST requests

 

How did we find out about these strange 500 Internal Server errors?

A few of our customers were getting sometimes strange 500 Internal Server errors when running load tests against their application even though when they were trying to make the GET or POST request from the browser it was working without a problem.

We decided to give them a hand finding why this might happen. The answer to the puzzle is quite simple but unless you know about the problem it might take a few hours to get to the bottom of the it.

The problem is that many web applications by default do not take into consideration the fact that some of the following headers might not be present in the client requests:

Accept:application/json;charset=utf-8,*/*
Accept-Encoding:gzip, deflate, sdch, br
Accept-Language:en-US,en;q=0.8,ro;q=0.6
Cache-Control:no-cache
Connection:keep-alive
Host:your_host:8080
Pragma:no-cache
Referer:https://your_host:8080/ui/index
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36

Why a lot of web applications do not consider the need to check that these headers are really sent in the user request ?

The answer is very simple, because all the browsers by default add these headers to all the requests.

 

What did we decide to implement in the LoadFocus platform to help our customers ?

For helping our customers we decided to add the possibility for the user to get all those headers added to their requests by only clicking one button.

Also we decided to add a few hints that will be displayed on the result page in case the requests return 500 Internal Server error.

Filed under Automated Website Testing & Monitoring, Selenium WebDriver, UI Testing.

We are going to present how you can mouseover an web element using Selenium WebDriver. The code below is straight forward:

  • first we identify the element to be hovered in the web page, here is how you can find web elements using Selenium WebDriver.
  • hover (mouseover) functionality is provided in Selenium WebDriver with the help of the Actions class, which provides the ability to move the mouse over an element.
WebElement web_Element_To_Be_Hovered = webDriver.findElement(By.cssSelector(selector_For_Web_Element_To_Be_Hovered));
Actions builder = new Actions(getDriver());
builder.moveToElement(web_Element_To_Be_Hovered).build().perform();

The build() method generates a composite action containing all actions so far, ready to be performed (and resets the internal builder state, so subsequent calls to build() will contain fresh sequences).

Also, if we want to click a web element after hovering the first element, we can do that by waiting for the element to be clickable, in order to interact with it.


WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(selector_For_Element_To_Be_Click_After_Hover)));
driver.findElement(By.cssSelector(selector_For_Element_To_Be_Click_After_Hover)).click();

The most important part is identifying the element right after the first web element was hovered (mouseover), otherwise we’ll get an exception that the element is not available.

Basically, you use the Actions to hover and the standard WebDriver method click, this way you could hover and then click.

 

Selenium WebDriver provides multiple options to interact with web elements with the Actions class. In our case, for mouseover (hover) functionality we can use the following 3 methods:

  1. moveToElement(WebElement toElement)
    • Moves the mouse to an offset from the top-left corner of the element
  2. moveToElement(WebElement toElement, int xOffset, int yOffset)
    • Moves the mouse from its current position (or 0,0) by the given offset. If the coordinates provided are outside the viewport (the mouse will end up outside the browser window) then the viewport is scrolled to match.
  3. moveByOffset(int xOffset, int yOffset)
    • Performs a context-click at middle of the given element. First performs a mouseMove to the location of the element.

 

More details related to Selenium WebDriver are available in the Video Course on How to Select a Dropdown in Selenium WebDriver.

With LoadFocus.com you can easily automate the repetitive manual testing of your site, schedule your automated tests to run from cloud instances at scheduled times.
We’ll notify you if something goes wrong on Slack or by Email. View detailed test reports with screenshots and videos of the bug in action

 

Filed under Cloud Services, Test Automation.

We’ve created a video to present an overview of LoadFocus services offered:

Please see below the full video.

 

LoadFocus.com is a All-In-One Cloud Testing Platform for Load Testing and Performance Testing, Website Speed Testing, Automated Website Testing and Mobile Emulation for Websites, Mobile Applications and API Endpoints.