Saturday, October 7, 2017

Useful Selenium code need to know


Refresh Page

driver.navigate().refresh();

Navigate On The Browser

driver.navigate().back();
driver.navigate().forward();

Focus On A Textbox Element

WebElement element  = driver.findElement(By.id("element-id"));
element.sendKeys("");

Overwrite On Textbox

WebElement element = driver.findElement(By.id("element-id"));
element.clear();
element.sendKeys("new input value");

Check If An Element Is Visible

WebElement element  = driver.findElement(By.id("element-id"));
if(element instanceof RenderedWebElement) {
System.out.println("Element visible");
} else {
System.out.println("Element Not visible");
}

Check If An Element Exists

driver.findElements(By.id("element-id")).size()!=0

Wait For Element To Be Available


WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("id123")));

 

Mouseover Action To Make Element Visible Then Click

Actions actions = new Actions(driver);
WebElement menuElement = driver.findElement(By.id("menu-element-id"));
actions.moveToElement(menuElement).moveToElement(driver.findElement(By.xpath("xpath-of-menu-item-element"))).click();

Wednesday, January 27, 2016

Install TestNG in Eclipse



-Run Eclipse.exe
-Help menu > Install New Software…

Type “http://beust.com/eclipse” in “Work with” checkbox and click “Add” button

Select  “TestNG” and click “Next”  and follow instruction to install



This will be start to install.
Restart Eclipse after the installation is done.
Now, when need you can add Testng class:

On New window, select TestNG class > Next


Install Maven in Eclipse



-Run Eclipse.exe
-In Eclipse:
Help menu > Eclipse Marketplace…


Seach for Maven

Select Maven and click Install button.
Maven start install, you wait until the Maven complete, let close Eclipse and run Eclipse again to start create Maven project.

Sunday, January 17, 2016

Download and run eclipse

1. Before downloading eclipse, you have to know what Operating system in your computer (64 bit/32 bit). If you don't know what it is just click on "computer" --> right click and choose "Properties", on the popup window you can see the system type as the photo below

2. Launch a browser and navigation to http://www.eclipse.org/downloads/
You can choose a version for your purpose, I choose the first one. And base on the system type of the window you click on "32 bit" or "64 bit" to download

3. On the download page, you can choose any server to download by click on "download" button at the server you like

4. Click on "ok" button on dialog window to start download
5. Extract File from the zip file
6. Click on eclipse.exe to run

Choose the path of Workspace  and then click "ok" button
The eclipse window is shown as below


Eclipse Shortcuts

Beside common shortcuts (Ctrl+C, Ctrl+V, Ctrl+F and so on), below is list of shortcuts that help you save a lot of time when you work on Eclipse


Content Assist
 Ctrl + Space
Quick Fix
 Ctrl + 1
Parameter Hints
 Ctrl + Shift + Space
Line comment
 Ctrl + /
Remove line comment
 Ctrl + \
Block comment  Ctrl+ shift + /
Remove block comment  Ctrl + shift + \
Ident
 Ctrl+I
Format
 Ctrl + Shift + F
Toggle Line Breakpoint
 Ctrl+Shift+B
View code of a method  Ctrl + click
Debug step into  F5
Debug step over  F6