Skip to content

Instantly share code, notes, and snippets.

View 4M01's full-sized avatar
🏠
Working from home

Amol Chavan 4M01

🏠
Working from home
View GitHub Profile
@4M01
4M01 / getParentElement.java
Last active May 9, 2016 07:58
Finding Parent Element of Known Element in Selenium/WebDriver
protected WebElement getParentElement(WebElement element){
WebElement parentElement=null;
if(element !=null){
parentElement=element.findElement(By.xpath(".."));
}
}
@4M01
4M01 / MongoServices.java
Last active July 20, 2018 05:50
Singleton MongoClient for Java Application
import com.mongodb.*;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.bson.Document;
import tests.TestBaseSetup;
import java.util.Arrays;
import java.util.Properties;
/**
* Created by Amol Chavan on 03-06-2016.
*/
@4M01
4M01 / Config.properties
Created June 12, 2016 14:26
Separate properties file which has parameters to connect with MongoDB server.
wd
@4M01
4M01 / DoubleClick.java
Last active June 21, 2016 16:25
Perform double click on page to get the page back from blacked-out state when notification poped-up.
public void doDoubleClick(){
WebElement body = driver.findElement(By.tagName("body"));
Actions actions= new Actions(driver).doubleClick(body);
actions.build().perform();
}
@4M01
4M01 / DriverFactory.java
Last active June 22, 2016 03:04
Create object of chromedriver which will block push notification.
public class DriverFactory {
public static WebDriver createInstance(){
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("disable-notifications");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver();
@4M01
4M01 / ObjectMap.java
Last active July 10, 2016 09:40
ObjectMap java is class that helps us to build Object Repository in selenium webdriver.
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
public class ObjectMap extends ActionUtilities{
Properties properties;
@4M01
4M01 / TestRuuner.java
Last active July 10, 2016 19:21
Simple Test Runner
import com.utilities.ObjectMap;
import org.openqa.selenium.firefox.FirefoxDriver;
/**
* Created by Amol Chavan on 11-07-2016.
*/
public class TestRunner {
public static void main(String[] args){
ObjectMap objectMap = new ObjectMap("Login.properties");
FirefoxDriver driver = new FirefoxDriver();
@4M01
4M01 / HighlightElement.java
Last active July 16, 2016 18:49
Java method to highlight webelement.
public void highlightElement(WebElement element) {
for (int i = 0; i < 5; i++) {
WrapsDriver wrappedElement = (WrapsDriver) element;
JavascriptExecutor driver = (JavascriptExecutor)
wrappedElement.getWrappedDriver();
driver.executeScript("arguments[0].setAttribute('style',arguments[1]);",
element, "color: green; border: 5px solid green;");
driver.executeScript("arguments[0].setAttribute('style',arguments[1]);",element, "");
}
@4M01
4M01 / DriverFactory.java
Created September 10, 2016 13:37
createInstance() is method that returns Chrome WebDriver object with Proxy setting unchecked.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
/**
* Created by Amol Chavan on 9/10/2016.
*/
public class DriverFactory {
@4M01
4M01 / newTab.java
Last active September 19, 2016 18:49
Open a blank tab in a browser using Selenium WebDriver for Windows. Please check http://qaperspective.blogspot.in/2016/09/open-new-tab-using-Selenium-WebDriver.html
driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL + "t");