Posts

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

Webdriver - Set browser width and height

Selenium WebDriver allows resizing and maximizing window natively from its API. We use 'Dimension' class to resize the window. Lets take the help of Selenium WebDrivers Dimension Class and declare object say 'd' by initializing it with width and height as 420X600 as shown below: Remember, We need to import the statement 'import org.openqa.selenium.Dimension' import org.openqa.selenium.Dimension; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.Test; public class browser { @Test public void openBrowserwithGivenDimension () { WebDriver driver = new FirefoxDriver(); driver.navigate().to( " http://google.co.in" ); System.out.println(driver.manage().window().getSize()); Dimension d = new Dimension( 420 , 600 ); //Resize the current window to the given dimension driver.manage().window().setSize(d); } } We can set the size and perform testing with lo

How to install TestNG in Eclipse

Image
Steps to follow:           1)   Launch the Eclipse IDE and from Help menu, click “ Install New Software ”. 2) You will see a dialog window, click “ Add ” button. 3) Type name as you wish, lets take “ TestNG ” and type “ http://beust.com/eclipse/ ” as location. Click OK. 4) You come back to the previous window but this time you must see TestNG option in the available software list. Just Click TestNG and press “ Next ” button. 5) Click “ I accept the terms of the license agreement ” then click  Finish . 6) You may or may not encounter a Security warning, if in case you do just click  OK . 7) Click  Next  again on the succeeding dialog box until it prompts you to Restart the Eclipse. 8) You are all done now, just Click  Yes . 9) Proceed with your workplace. 10) After restart, verify if TestNG was indeed successfully installed. Right click on you pr