Posted in Java, QA, Tips

Useful scripts for Selenium in Java

selenium_icon

Selenium HQ is really useful for testing, you can find its info at Selenium Home Page . During working on it in Java projects, I found some scripts which help us save time for test cases implementation.

  • First is the necessary component in Selenium lib:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
  • Constructors:
WebDriverWait wait = new WebDriverWait(driver, 60);
WebDriver driver;
  • Collapse / Expand

This script is an action of Mouse when User clicks on an expand-icon for collapsing or expanding

JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("$('.expand-icon')[0].dispatchEvent(new MouseEvent('click'))");
  • Click on a button:
String buttonId = "//button[@id='button_id_here']";
driver.findElement(By.xpath(buttonId)).click();
  • Check a webpage exist or not
String pageTitle = "//span[contains(.,'Page_Title')]";
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(pageTitle)));
  • Find a button
String buttonElement = "//button[@title='Button text here']";
WebElement buttonElement = driver.findElement(By.xpath(buttonElement ));
  • Find a content:
String contentId = "//span[@id='Content ID Here']";
WebElement contentElement = driver.findElement(By.xpath(contentId ));
  • Others (continues)

 

 

If this topic is helpful for you. Please share 🙂

 

Advertisements
Posted in Tips

[Tips] Helpful commands for OS

  • MAC
  1. Find IP: ifconfig | grep ‘inet
  2. Go to /usr/local folder:

Method 1: From the Terminal, type “open -a Finder /usr/local/bin”.

Method 2: From Finder’s “Go” menu, select “Go to folder…”. That’ll bring up a window in which you can type “/usr/local/bin”.

 

  • Window
  1. Find IP: ipconfig
  2. OS info: dxdiag