This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Good Class Names | |
public class InsuranceCost | |
//Bad Class Names | |
public class Insurancecost | |
public class insurancecost | |
public class Insurance_cost |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void alerts() { | |
driver.get("https://the-internet.herokuapp.com/javascript_alerts"); | |
driver.findElement(By.xPath("//*[contains(normalize-space(text()), 'Click for JS Alert')]")).click(); | |
driver.switchTo().alert().accept(); | |
driver.findElement(By.xPath("//*[contains(normalize-space(text()), 'Click for JS Prompt')]")).click(); | |
Alert inputAlert = driver.switchTo().alert(); | |
String text = inputAlert.getText(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void frames() { | |
driver.navigate().to("https://the-internet.herokuapp.com/nested_frames"); | |
WebElement defaultFrame = driver.findElement(By.name("frame-top")); | |
driver.switchTo().frame(1); | |
Assert.assertEquals("BOTTOM", driver.findElement(By.tagName("body")).getText()); | |
driver.switchTo().parentFrame(); | |
driver.switchTo().frame("frame-top"); | |
driver.switchTo().frame("frame-left"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void windowFrames() { | |
driver.navigate().to("https://the-internet.herokuapp.com/windows"); | |
JavascriptExecutor js = (JavascriptExecutor) driver; | |
js.executeScript(("window.open('https://the-internet.herokuapp.com/windows/new')")); | |
String originalWindow = driver.getWindowHandle(); | |
Set handles = driver.getWindowHandles(); | |
handles.remove(originalWindow); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JavaScriptExecutor js = (JavaScriptExecutor) driver; | |
js.executeScript("alert('Hello World!')"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// hover | |
action.moveToElement(element).build().perform(); | |
// drag and drop | |
action.dragAndDrop(element, element2).build().perform(); | |
// click-pause-release | |
action.clickAndHold(element).pause(100).release().build().perform); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Performs a modified key press. | |
keyDown(java.lang.CharSequence key); | |
// Performs a modified key release. | |
keyUp(java.lang.CharSequence key); | |
// Sends keys to the active element. | |
sendKeys(java.lang.CharSequence key); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Clicks in the middle of the given element. | |
click(WebElement target); | |
// Clicks (without releasing) at the current mouse location. | |
clickAndHold(WebElement target); | |
// Performs a context-click at middle of the given element. First performs a mouseMove to the location of the element. | |
contextClick(WebElement target); | |
// Performs a double-click at middle of the given element. | |
doubleClick(WebElement target); | |
// A convenience method that performs click-and-hold at the location of the source element, | |
// moves to the location of the target element, then releases the mouse. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WebElement element = driver.findElement(By.id("sign-in")); | |
Actions action = new Actions(driver); | |
action.click(Element).build().perform(); |