Posts

Download and validate file using webdriver,wget

Image
Downloading Files WebDriver has no capability to access the Download dialog boxes  presented by browsers when you click on a download link or button. However, we can bypass these dialog boxes using a separate program called "wget". What is Wget? Wget is a small and easy-to-use command-line program used to automate downloads . Basically, we will access Wget from our WebDriver script to perform the download process.   Setting up Wget Step 1 In your C Drive, create a new folder and name it as "Wget". Download wget.exe  here  and place it in the Wget folder you created from the step above. Step 2 Bring up the System Properties window by pressing Win + Pause on your keyboard. Click on "Advanced System Settings" Click on the "Environment Variables". Step 3 In the Environment Variables dialog box, in the "System variables" section, scroll down the list until you find "

How To Highlight Locators In WebDriver Test Cases

It's likely that you'll run into odd test behavior that makes you question the locators you're using in a test. But how do you interrogate your locators to make sure they are doing what you expect? By leveraging some simple JavaScript and CSS styling, you can highlight a targeted element on the page so you can visually inspect it to make sure it's the one you want. import org.junit.After ; import org.junit.Before ; import org.junit.Test ; import org.openqa.selenium.WebDriver ; import org.openqa.selenium.By ; import org.openqa.selenium. JavascriptExecutor ; import org.openqa.selenium.WebElement ; import org.openqa.selenium.firefox. FirefoxDriver ; public class HighlightElement { WebDriver driver ; JavascriptExecutor js ; @Before public void setUp () throws Exception { driver = new FirefoxDriver (); js = ( JavascriptExecutor ) driver ; } @After public void tearDown () throws Exce

Hybrid and Native Apps ?

The moment you consider investing in a mobile app, you’re immediately faced with a barrage of terminology. What’s the difference between iOS and Android? What are native, hybrid and web apps? More importantly, which is most appropriate for your and your app? 
 Native Apps Native apps are what typically springs to mind when you think of an app. You download them from the App Store or Google Play, they sit within your device’s applications and you launch them by tapping their icon. Developing Native Apps Each mobile platform offers developers their own development tools, interface elements and standardised SDK. This should enable any professional developer to develop a native app relatively easily. There are a number of advantages to writing apps in this way: •    They offer the  fastest, most reliable and most responsive experience to users . •    They can tap into the wider functionality of the device; including the camera, microphone, compass, accelerometer a

How To Access Basic Auth with Selenium

The Problem Sometimes you'll work with applications that are secured behind  Basic HTTP Authentication  ( Basic Auth). In order to access them you'll need to pass credentials to the site when requesting a page. Otherwise you'll get a system level pop-up prompting you for a username and password -- rendering Selenium helpless. Before Selenium 2 we were able to accomplish this by injecting credentials into a custom header. But now the cool kid way to do it it was something like  BrowserMob Proxy . Some people are solving this with browser specific configurations too. But all of this feels heavy. Instead, let's look at a simple approach that is browser agnostic and quick to setup. A Solution By specifying the username and password  in the URL  when visiting a page with Selenium, we can a side-step the system level dialog box from Basic Auth and avoid the need to set up a proxy server. This approach will work for both HTTP or HTTPS pages. Let's take a look

Find out broken links / images on website using webDriver

Broker Links:  By just seeing the Links in the UI, we may not be able to confirm if that link is working or not until we click and verify it. To achieve this, we can use HttpClient library to check status codes of the URLs on a page. If request was NOT processed correctly, then the HTTP status codes may not return 200 status code. We can easily say whether the link is broken or not with status codes. Now let us jump into the example, First we will try to find all anchor tags on the page by using Webdriver. By using the below syntax: We need to iterate through each link and verify request response Status codes and it should be 200 if not, we will increment invalid links count Let us look into the example : package com.linked; import java.util.List; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.HttpClientBuilder; import org.openqa