Java tutorial
/* * Copyright 2014. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.davidgaskins.com/license * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.davidgaskins.learningtounittest; import java.io.FileNotFoundException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; /** * * @author David Gaskins <david.s.gaskins@gmail.com> * */ public class MoneyMaker { public static WebDriver driver; public static final double timeToWait = 1; public MoneyMaker() { driver = new FirefoxDriver(); } public void signInToMicrosoftAccount() { driver.get("http://bing.com"); navigateToLoginPage(); enterCredentials(); } /** * navigate to the bing login page */ private void navigateToLoginPage() { String dropdownToLoginLink = ".//*[@id='id_s']"; Utilities.clickButton(driver, dropdownToLoginLink); String microsoftAccountLink = ".//*[@id='b_idProviders']/li[1]/a/span[2]"; Utilities.clickButton(driver, microsoftAccountLink); } /** * enter the credentials that the user provides */ public void enterCredentials() { try { // make the credential manager CredentialsManager m = new CredentialsManager( "/Users/david/dev/webdriver/LearningToUnitTest/src/main/java/com/davidgaskins/learningtounittest/credentials.txt"); String username = m.getUsername(); // input the username String pathToUserName = ".//*[@id='i0116']"; Utilities.inputString(driver, pathToUserName, username); // input the password String password = m.getPassword(); String pathToPassword = ".//*[@id='i0118']"; Utilities.inputString(driver, pathToPassword, password); // click the sign in button String pathToSignIn = ".//*[@id='idSIButton9']"; Utilities.clickButton(driver, pathToSignIn); } catch (FileNotFoundException fnf) { Utilities.cleanUpSystem(fnf); } } /** * Navigate to the bing webpage, and performs a bing search * @param toSearch */ public void doBingSearch(String toSearch) { driver.get("http://bing.com"); // set the string that we want to search on String pathToSearchBox = ".//*[@id='sb_form_q']"; Utilities.inputString(driver, pathToSearchBox, toSearch); // click the button String searchButton = ".//*[@id='sb_form_go']"; Utilities.clickButton(driver, searchButton); } }