Selenium WebDriver Test Automation UI Testing

2 minutes read

Create automated website tests for free with LoadFocus.com.

If you want to take snapshots of the browser while running tests using Selenium Webdriver these are some ways to do it.
Basically the only thing you need to do is use the class below to take snapshots of the urls you want:

package com.webdriver.automation.tests;

import java.io.File;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TestUtils {

private final static Logger log = LoggerFactory.getLogger(TestUtils.class);

public static void takeDriverSnapShot(WebDriver driver, String screenSnapshotName) {
File browserFile = new File(System.getProperty("java.io.tmpdir") + File.separator +screenSnapshotName + ".png");
snapshotBrowser((TakesScreenshot) driver, screenSnapshotName, browserFile);
}

private static void snapshotBrowser(TakesScreenshot driver, String screenSnapshotName, File browserFile) {
try {

File scrFile = driver.getScreenshotAs(OutputType.FILE);
log.info("PNG browser snapshot file name: \"{}\"", browserFile.toURI().toString());

FileUtils.deleteQuietly(browserFile);
FileUtils.moveFile(scrFile, browserFile);
} catch (Exception e) {
log.error("Could not create browser snapshot: " + screenSnapshotName, e);
}
}

public static void main(String[] args){
WebDriver driver = new FirefoxDriver();
driver.get("http://google.com");

TestUtils.takeDriverSnapShot(driver, "google_com");
driver.close();
}
}

Have a look at the main method which uses the code for taking a snapshot.

If your using TestNG as an unit testing framework, it’s even easier to take screen shots.
The code below takes screenshots of failed tests and stores in the Surefire reports directory: “/target/surefire-reports/screenShots/”.

@AfterMethod(alwaysRun = true)
public void afterMethod(ITestResult result) throws Exception {
if (!result.isSuccess())
takeScreenShoot(threadDriver, result.getMethod());

// Quit environment.
getDriver().close();
getDriver().quit();
}

public void takeScreenShoot(ThreadLocal threadDriver, ITestNGMethod testMethod) throws Exception {
WebDriver augmentedDriver = new Augmenter().augment(threadDriver.get());
File screenshot = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE);
String nameScreenshot = testMethod.getMethodName();
String path = getPath(nameScreenshot);
FileUtils.copyFile(screenshot, new File(path));
Reporter.log("<a href="file://&quot;" target="_blank">" + this.getFileName(nameScreenshot) + "</a>");
}

private String getFileName(String nameTest) throws IOException {
DateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy_hh.mm.ss");
Date date = new Date();
return dateFormat.format(date) + "_" + nameTest + ".png";
}

private String getPath(String nameTest) throws IOException {
File directory = new File(".");
String newFileNamePath = directory.getCanonicalPath() + "/target/surefire-reports/screenShots/" + getFileName(nameTest);
return newFileNamePath;
}

Use Selenium WebDriver to take screenshots of failed tests to have a better understanding of your failures and debug webdriver tests easier.

Also you can take a look on the previous Selenium WebDriver blog post to locate elements in a page.

Selenium WebDriver Test Automation UI Testing

< 1 minute read

Create automated website tests for free with LoadFocus.com.

If you need to run Selenium WebDriver UI tests in a browser that sends the traffic through a proxy, here is a code example of a Selenium test.
In this article we will show how easy it is to configure WebDriver to use a proxy by presenting a small code snippet that uses the FireFox driver and for which we set the HTTP, SSL and FTP proxy:

package com.webdriver.automation.tests;

import java.util.ArrayList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.Proxy.ProxyType;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

public class WebdriverUsingProxy {

private List<String> urlList = new ArrayList<String>();

@Before
public void setup() {
urlList.add("http://news.bbc.co.uk");
urlList.add("https://news.google.com");
}

@Test
public void passTraffixThroughProxyTest() {
String httpProxy = "10.10.1.3:8080";
String sslProxy = "10.10.1.3:8080";
String ftpProxy = "10.10.1.3:8080";

DesiredCapabilities capability = new DesiredCapabilities();
addProxyCapabilities(capability, httpProxy, sslProxy, ftpProxy);

for (String url : urlList){
WebDriver driver = new FirefoxDriver(capability);
driver.get(url);
driver.close();
}
}

public static DesiredCapabilities addProxyCapabilities(DesiredCapabilities capability, String httpProxy, String sslProxy,
String ftpProxy) {
Proxy proxy = new Proxy();
proxy.setProxyType(ProxyType.MANUAL);
proxy.setHttpProxy(httpProxy);
proxy.setSslProxy(sslProxy);
proxy.setFtpProxy(ftpProxy);

capability.setCapability(CapabilityType.PROXY, proxy);
capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
return capability;
}
}

In the code above we set the proxy type to manual and we’ve set the HTTP, SSL and FTP proxy to 10.10.1.3:8080. This is done using the Proxy object and setting the desired capability, pretty easy 🙂

If you want to see a easy and complete way to locate web elements check our last Selenium WebDriver blog post.

Have fun passing traffic through proxy in your tests. Also check Load Focus, our Cloud Load and Performance Application Testing Service. You can stress your app/website/API with thousands of concurrent users from all over the world.

General

< 1 minute read

We think easier and simpler is better. Discover how your website or app behaves under custom conditions: number of concurrent users, regions all around the world, custom number of requests or delay between users.

We selected the features we think suit the needs of every business owner, developer, quality assurance or operations person. Just let us know if you think something is missing. Thanks in advance.

New release includes

  • takes less than 1 minute to configure your load test
  • load test type: per duration and per number of request
  • multiple locations
  • GET, POST, PUT and DELETE HTTP methods supported
  • we support: request query parameters, cookies, HTTP headers, POST body, Basic HTTP Authentication
  • live load test results
  • new UI and workflows

Click here to signup. Enjoy!

load testing live monitoring

 

 

Apache JMeter Load Testing Test Automation Uncategorized

< 1 minute read

HTTP POST request is used for sending data to a server. You can use POST requests for upload a file or submitting a web form, make sure that the receiving application agrees on the format.
Additional headers are sent with the POST request: Content-Type: header which is usually application/x-www-form-urlencoded and the Content-Length: header gives the length of the URL-encoded form data. These additional headers are used to describe the message body.

The POST body is the block of data sent with the request and the request URI is not a resource to retrieve; it’s usually an application to handle the data you’re sending.
The HTTP response is normally application response to your file upload request or form submission, not a static file.

You can check related posts, what is HTTP, and what is HTTP GET request.

Use LoadFocus.com for load testing your application with thousands of concurrent connections. You can create GET, POST, PUT and DELETE requests to you website. API endpoints or web application.

Page Load Time Test Automation Web Resources

< 1 minute read

The HTTP “GET” method is used just for retrieving data and should have no other effect.

When you enter a URI in the browser or you click on a link you are executing a GET request. Here are some characteristics of GET requests: can be cached, bookmarked, appear in browser history.

You can easily find details about all the requests made, when accessing an URI, by opening the Developer Tools in the browser and inspecting the network traffic.

GET requests don’t necessarily have to be made from the browser, you can make AJAX GET requests and use other tools in this purpose.

Test Automation Web Testing Books

< 1 minute read

The HTTP (Hypertext Transfer Protocol) is an application protocol designed to enable communications between clients and servers, and the foundation of data communication for the World Wide Web.
HTTP provide a standard way of communication between client (browsers) and web servers.

HTTP works as a request-response protocol, the web browser may be the client, and an application on a computer that hosts a web site may be the server.
For example when the client (browser) submits an HTTP request to the server, the server returns a response to the client with additional information.

HTTP is a stateless protocol because each command is executed independently of the previous commands.

From the browser, in order to access a URL you have to add the http:// command before the URL address (http://www.example.com). These days you can skip it, and the browsers will add it for you automatically when you enter an address in the URL bar.
If you want to access from the browser a HTTPS URL (Hypertext Transfer Protocol over Secure) you have to specify it manually.

Performance Testing

< 1 minute read

To understand the load test results better, we’ve added in the LoadFocus.com test results page the following short explanations for the below metrics. Hope they will help interpret results better:

What is “Response Time”?

Response Time measures the performance of an individual transaction or query and is the amount of time from the moment that a user sends a request until the time that the application indicates that the request has completed.

What is the “90% Line”?

90% Line (90 percentile of the response times)represents one of the most interesting metrics and shows that “90% of the samples finished within 0-x time” or “90% of the samples took no more than this time”

What is the “Average Response Time”?

The “Average Response Time” is a good number to know, however in a business-to-business service application, it doesn’t matter if the average response time is 500ms, if the 90% line is 1.5 seconds. From a software developer perspective, if the 50% and 90% lines are far appart, the application fluctuates a lot.

What is “Latency”?

Latency , a synonym for delay, is the time for a specific block of data to get from one point to another. Latency is measured by sending a packet that is returned to the sender and the round-trip time is considered the latency.
Latency + Processing Time = Response Time

What is “Throughput”?

Throughput indicates the number of transactions per second an application can handle, the amount of transactions produced over time during a test.

Transactions per second

Transactions per second refer to the number of database transactions completed in one second.