Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static {
- URL = "https://website.com";
- DEFAULT_WAIT_TIME = 60;
- SYSTEM_ID = "IDnumber";
- USERNAME = "Username1";
- PASSWORD = "Password1";
- }
- import static org.junit.Assert.fail;
- import java.util.concurrent.TimeUnit;
- import org.junit.After;
- import org.junit.Before;
- import org.junit.Test;
- import org.openqa.selenium.*;
- import org.openqa.selenium.firefox.FirefoxDriver;
- import org.openqa.selenium.support.ui.ExpectedConditions;
- import org.openqa.selenium.support.ui.WebDriverWait;
- public class Login {
- private WebDriver driver;
- private String baseURL;
- private StringBuffer verificationErrors = new StringBuffer();
- @Before
- public void setUp() throws Exception {
- //driver = new FirefoxDriver();
- //baseURL = Environment.URL;
- driver.manage().timeouts().implicitlyWait(Environment.DEFAULT_WAIT_TIME, TimeUnit.SECONDS);
- }
- public static void doLogin(WebDriver driver, String baseURL) {
- WebDriverWait wait = new WebDriverWait(driver, Environment.DEFAULT_WAIT_TIME);
- System.out.println("Log in to trunk...");
- driver.get(baseURL);
- wait.until(ExpectedConditions.presenceOfElementLocated(By.id("company_id")));
- if (driver.findElement(By.xpath("//div[span='Log In']/span")).isEnabled()) {
- System.out.println(" 1 - 'Login' page is opened");
- } else {
- System.out.println(" !ERROR! - Can NOT open 'Login' page");
- driver.findElement(By.id("This is to throw exception if Can NOT open 'Login' page"));
- }
- driver.findElement(By.id("company_id")).clear();
- driver.findElement(By.id("company_id")).sendKeys(Environment.SYSTEM_ID);
- driver.findElement(By.xpath("//input[@name='username']")).clear();
- driver.findElement(By.xpath("//input[@name='username']")).sendKeys(Environment.USERNAME);
- driver.findElement(By.id("c_password")).clear();
- driver.findElement(By.id("c_password")).sendKeys(Environment.PASSWORD);
- System.out.println(" 2 - Info filled");
- //I removed the rest of the code that finishes the login because
- //I don't think it is needed for demonstration
- }
- @Test
- public void main() {
- doLogin(driver, baseURL);
- }
- @After
- public void tearDown() throws Exception {
- driver.quit();
- String verificationErrorString = verificationErrors.toString();
- if (!"".equals(verificationErrorString)) {
- fail(verificationErrorString);
- }
- }
- }
- import static org.junit.Assert.fail;
- import java.util.concurrent.TimeUnit;
- import org.junit.After;
- import org.junit.Before;
- import org.junit.Test;
- import org.openqa.selenium.By;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.firefox.FirefoxDriver;
- import org.openqa.selenium.ie.InternetExplorerDriver;
- import org.openqa.selenium.support.ui.ExpectedConditions;
- import org.openqa.selenium.support.ui.Select;
- import org.openqa.selenium.support.ui.WebDriverWait;
- public class Transaction {
- private WebDriver driver;
- private String baseURL;
- private StringBuffer verificationErrors = new StringBuffer();
- public static String country = "22";
- public static String ammount = "500";
- @Before
- public void setUp() throws Exception {
- // System.setProperty("webdriver.ie.driver", "../IEDriverServer.exe");
- // driver = new InternetExplorerDriver();
- driver = new FirefoxDriver();
- baseURL = Environment.URL;
- driver.manage().timeouts().implicitlyWait(Environment.DEFAULT_WAIT_TIME, TimeUnit.SECONDS);
- }
- public static void doTransaction(WebDriver driver) {
- WebDriverWait wait = new WebDriverWait(driver, Environment.DEFAULT_WAIT_TIME);
- System.out.println("Performing transaction...");
- // This is where the transaction code is ......
- }
- @Test
- public void transaction() {
- //Login first
- Login.doLogin(driver, baseURL);
- // Transaction
- doTransaction(driver);
- }
- @After
- public void tearDown() throws Exception {
- driver.quit();
- String verificationErrorString = verificationErrors.toString();
- if (!"".equals(verificationErrorString)) {
- fail(verificationErrorString);
- }
- }
- }
- <suite>
- <test name="firstTest">
- <parameter name="username" value="username1"/>
- <parameter name="password" value="password1"/>
- ....
- </test>
- <test name="secondTest">
- <parameter name="username" value="username2"/>
- <parameter name="password" value="password2"/>
- ....
- </test>
- </suite>
- @Parameters({"username", "password"})
- @BeforeTest
- public void beforeTest(String username, String password) {
- this.getDriver().get("http://mypage.com");
- this.getDriver().findElement(By.id("usernameInputField")).sendKeys(username);
- this.getDriver().findElement(By.id("passwordInputField")).sendKeys(password);
- ...
- }
Add Comment
Please, Sign In to add comment