Java Coding Standards
Example
Note: WE NEED A GOOD EXAMPLE for the main method! This one breaks a lot of the rules… please feel free to insert a good example.
// start out with your package name
package com.example;
// next import things you need from the Selenium test framework
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;
import org.testng.TestNG;
// import extra things you want to use from Java
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
try {
driver.get("https://google.com/ncr");
driver.findElement(By.name("q")).sendKeys("cheese" + Keys.ENTER);
WebElement firstResult = wait.until(presenceOfElementLocated(By.cssSelector("h3>div")));
System.out.println(firstResult.getAttribute("textContent"));
} finally {
driver.quit();
}
}
}
Principles
Naming Conventions
--
GenericUltranaut - 14 Apr 2020