Showing posts with label Read data from Properties file using Java Selenium. Show all posts
Showing posts with label Read data from Properties file using Java Selenium. Show all posts

Mouse hover action in Selenium Webdriver

Mouse hover action in Selenium Webdriver,While working with web application menus you will face a problem that mouse hover,once mouse hover then only remaining menus will be displayed.In this post you will learn Mouse hover action in selenium webdriver using Web elements ,Actions classes in Selenium Web Driver.Below are the way of doing this is by using Action in class.

Mouse hover action in Selenium WebDriver


Mouse hover action in Selenium Webdriver

Method 1:

Here directly using link Text to check mouse hover for main menu or sub menu to identify the elements in webpage.

WebElement element = driver.findElement(By.linkText("More.."));
Actions action = new Actions(driver);
action.moveToElement(element).build().perform();
driver.findElement(By.linkText("SQL")).click();

Some times it will not work then we can use another method as below to select SQL link from More.. menu according to above menu.

Also Read

Datadriven Framework using selenium
Verify element is enable in Selenium
Read Data From properties file using Selenium
Launch Firefox Browser using GeckoDriver
Selenium-Testng examples to execute multiple classes
Selenium WebDriver Methods
Generate HTML Reports using Selenium

For some applications mouse over will work upto certain fraction of seconds at that situation we can go for below method easily to identify the elements.This method will work deffinately with the help of action.moveToElement(element).click().build.perform

package com.gmail.account;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import org.apache.tools.ant.taskdefs.Exit;
import org.openqa.selenium.By;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.Test;

public class MouseOver{

WebDriver driver;
String baseUrl;

@Test
public void mouseHover(){

driver = new FirefoxDriver();
String baseUrl = "http://www.wikishown.com";
driver.get(baseUrl);
driver.manage().window().maximize();
//Use Action
Actions action = new Actions(driver);
//Mouse over on elements using WebElments
WebElement element = driver.findElement(By.linkText("More.."));
//Now mouse should move to particular element
action.moveToElement(element).click().build().perform();
Thread.sleep(2000);
//Identifying the SubMenu and click on Subbmenu
action = new Actions(driver);
WebElement subelement=driver.findElement(By.linkText("SQL"));
//Thread.sleep(5000);
action.moveToElement(subelement).click().build().perform();

}

}

Run above script as Right Click on Script - Run As  - TestNG Test.

Conclusion:

I am expecting method 2 is very useful in your projects,in case it is working please provide your valuable comments and suggestions and please feel free to contact me through comment.Thank you for reading.

Read data from Properties file using Java Selenium webdriver

We can easily read properties from object repository file or some other files using object type properties,In this post example you will learn perfect knowledge about Read data from Properties file using Java Selenium.Please Read Selenium WebDriver Tutorial.Properties files are using in Java programming which is mainly using for configuration data in their project like data base configuration details,GUI Element data etc.In Selenium Test scripting you can use properties files to read the data from files to your Test scripts in order to maintain clean scripts and clear understanding of test scripts.

Read data from Properties file using Java Selenium webdriver
Properties file in Selenium WebDriver


Read data from Properties file using Java Selenium webdriver

In below example you will understand how to create properties file and read data from properties files ,please read full article to understand clearly and i have given brief explanation below the end of the code with each step so that you people can understand clearly.Let's see the below code.
package com.eu.examples;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.IOException;

import java.util.Properties;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.testng.annotations.Test;


public class PropertiesFilesSelenium {


//Read data from Properties file using Java Selenium

//OR= Object Repository:

public static WebDriver driver;

@Test

public void openBrowser() throws FileNotFoundException{


driver = new FirefoxDriver();

//using properties to create object

Properties property = new Properties();

//Call the file OR.propoeties file using FileInputStream

FileInputStream objFile = new FileInputStream</span></pre>
<pre><span style="font-size: medium;">("E:\\QTP Tutorials\\Selenium Automation\\ExtentUsages\\OR.properties");

//Load the properties File

try {

property.load(objFile);

} catch (IOException e) {

System.out.println(e.getMessage());

e.printStackTrace();

}


//Open Software Testing blogspot

driver.get(property.getProperty("baseURL"));

//Maximize the window

driver.manage().window().maximize();

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

System.out.println("Window is maximized");

//Click on Manual Testing menu

driver.findElement(By.xpath(property.getProperty("Manualtesting"))).click();

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

System.out.println("Clicked on Manual Testing menu");

//Click on QTP Tutorials

driver.findElement(By.xpath(property.getProperty("QTPTutorials"))).click();

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

System.out.println("Clicked on QTP Testing menu");

//Click on SeleniumTutorials

driver.findElement(By.xpath(property.getProperty("SeleniumTutorials"))).click();

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

System.out.println("Clicked on sELENIUM Testing menu");

//Click on LoadrunnerTutorials

driver.findElement(By.xpath(property.getProperty("LoadrunnerTutorials"))).click();

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

System.out.println("Clicked on Loadrunner Testing menu");


OUTPUT:

Once you run above program you will get below output in Eclipse console

Window is maximized
Clicked on Manual Testing menu
Clicked on QTP Testing menu
Clicked on sELENIUM Testing menu
Clicked on Loadrunner Testing menu
PASSED: openBrowser

===============================================
Default test
Tests run: 1, Failures: 0, Skips: 0
===============================================

Properties File

#Software Testing Application Object Properties#

baseURL=http://softwaretestutorials.blogspot.in

#Different Menu's Properties
Manualtesting=/html/body/div[4]/div[2]/div[2]/div[2]/div[1]/div[2]/div[2]/div[1]/div/div/ul/li[2]/a
QTPTutorials=/html/body/div[3]/div[2]/div[2]/div[2]/div[1]/div[2]/div[2]/div[1]/div/div/ul/li[3]/a
SeleniumTutorials=/html/body/div[3]/div[2]/div[2]/div[2]/div[1]/div[2]/div[2]/div[1]/div/div/ul/li[4]/a
LoadrunnerTutorials=/html/body/div[3]/div[2]/div[2]/div[2]/div[1]/div[2]/div[2]/div[1]/div/div/ul/li[5]/a

Read data from Properties file using Java Selenium Properties File Code Explanation:

Below details will give you brief details about above code in detail explanation,let's start understanding the code.

Properties property = new Properties();
In Above i have created one object under Properties() because wit this object you can load or read the properties file easily.

FileInputStream objFile = new FileInputStream("E:\\QTP Tutorials\\Selenium Automation\\ExtentUsages\\OR.properties");

FileinputStream in java is useful in reading the different files in order to get the data from specified file and here we are going to use this FileInputStream to load the file into our scripts.

try {
property.load(objFile);
} catch (IOException e) {
System.out.println(e.getMessage());
e.printStackTrace();
}

In order to load the FileinputStream file ,you can use above try catch block for load the file in order to avaoid IOException while executing the script.

driver.get(property.getProperty("baseURL"));

In order to read the data from Propoerties file just you need to use property.getProperty(String Key),here property is created object in properties i.e property and getProperty is a method to read the properties from property files.

Thank you for reading please share my post.