Automation Using Selenium Webdriver

Monday, 31 October 2016

How to get hidden webelements text in Selenium Webdriver using Java

How to get hidden webelements text in Selenium Webdriver using Java
import java.util.List;
 import java.util.concurrent.TimeUnit;
 import org.openqa.selenium.By;
 import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.WebElement;
 import org.openqa.selenium.firefox.FirefoxDriver;
 public class HiddenElementstext {
   public static void main(String[] args) throws InterruptedException {
     // create objects and variables instantiation    
     WebDriver driver = new FirefoxDriver();
     // maximize the browser window    
     driver.manage().window().maximize();
     // launch the firefox browser and open the application url
     driver.get("www.yahoo.com");
     //Set timeout    
     driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
     //Get input tag and store in List variable name is number_of_hiddenElements
     List<WebElement> number_of_hiddenElements = driver.findElements(By.tagName("input"));
     //Print total number of Input tag
     System.out.println(number_of_hiddenElements.size());
     for (int i = 0; i < number_of_hiddenElements.size(); i++) {
       // Print all hidden elements text
       if (number_of_hiddenElements.get(i).getAttribute("type").trim().equalsIgnoreCase("hidden")) {
         //Check empty text
         if (!(number_of_hiddenElements.get(i).getAttribute("value").trim().isEmpty())) {
           //Print hidden Element texts
           System.out.println("Hidden Element text = " + i + " " + number_of_hiddenElements.get(i).getAttribute("value").trim());
         }
       }
     }
     // quit Firefox browser
     driver.quit();
   }
 }  

General Framework Structure in Selenium

Test Automation Frameworks
What is Framework?

A Test automation framework is an integrated system that can have the rules, standards and guidelines of automation of a specific application.

This system integrates the generic libraries, test data sources, object details, configuration modules, reporting and logs.


General Framework Structure:

Advantages:
1) Robust, flexible and extensible and support test automation on diverse sets of web applications across domains.
2) User-friendly interface for creation and execution of test suites.
3) Re-usability of code.
4) Increases test coverage to enhance the quality and reliability of the end product.
5) Easy maintenance.
6)Automated HTML report generation and emailing of the same to all stake holders

Types of Test Automation Frameworks
Data Driven Testing Framework
Keyword Driven Testing Framework
Hybrid Testing Framework
Page Object Model
1)Page Object Model

Now a days, Page Object Model become very popular test automation framework in Selenium, where web application pages are represented as classes, and the all the web elements on the page are defined as variables on the class. All possible user interactions can be implemented as methods on the class.

Please find the link for Page Object Model in Selenium.

2) Data Driven Framework

If you observe several times while testing an application, it may be required to test the same functionality multiple times with the different set of input data, In that situation, if you hard-coded the test data to automation test scripts will not useful for reusability. So instead of hard-coded test data you have to store it in external files like excel, xml, properties file, database, csv.
So in order to test the application, you have to connect with external files and get the test data from them.

How to work with Firefox browser using Selenium 3.0 beta 1

How to work with Firefox browser using Selenium 3.0 beta 1

Recently selenium has launched Selenium 3.0 beta 1 jar.In this post I will show you How to work with Firefox browser using Selenium 3.0 beta 1 jar.

Please follow the below steps:
Step:1
Just like the other drivers available to Selenium from other browser vendors, Mozilla has released now an executable that will run alongside the browser

In order to work with Firefox browser using Selenium 3 beta 1 jar, you need to use separate a driver which will interact with Firefox browser called as "Geckodriver".

Please find below link for downloading latest version of geckodriver.

https://github.com/mozilla/geckodriver/releases/download/v0.9.0/geckodriver-v0.9.0-win64.zip

Step:2
System.setProperty("webdriver.gecko.driver", "path/to/geckodriver.exe");

Step:3
driver = new FirefoxDriver();

Note: Still if you are using old versions of selenium jars(selenium 2) then you can skip first two steps.

Sample Code:
public class SampleTest {

 public WebDriver driver;

 @Test
 public void setup(){

  System.setProperty("webdriver.gecko.driver", "E:/geckodriver.exe");
  driver = new FirefoxDriver();
  driver.manage().window().maximize();
  driver.get("http://www.facebook.com/");

  }

}