You are on page 1of 4

package testScript; import import import import import java.awt.AWTException; java.awt.Robot; java.awt.event.KeyEvent; java.lang.reflect.InvocationTargetException; java.util.concurrent.

TimeUnit;

import javax.mail.MessagingException; import javax.mail.internet.AddressException; import import import import import import import import import import org.openqa.selenium.By; org.openqa.selenium.WebDriver; org.openqa.selenium.WebElement; org.openqa.selenium.firefox.FirefoxDriver; org.openqa.selenium.interactions.Actions; org.openqa.selenium.support.ui.Select; org.testng.annotations.BeforeSuite; org.testng.annotations.DataProvider; org.testng.annotations.Test; org.openqa.selenium.Keys;

public class dataProvider { public public public public static static static static FirefoxDriver driver; String strTestURL = "http://qa.guru.com/login.aspx"; String privacyOption; String projectBudget;

@BeforeSuite public void start() { driver = new FirefoxDriver(); try{ System.out.println("Open the Guru Login Page.... ......................................."); driver.get(strTestURL); driver.manage().timeouts().implicitlyWait(20, Ti meUnit.SECONDS); }catch(Exception e){ e.printStackTrace(); } } @Test public static void guruEmpLogin() { driver.findElement(By.id("ucLogin_txtUserName_tx tUserName_TextBox")).sendKeys("emptest"); driver.findElement(By.id("ucLogin_txtPassword_tx tPassword_TextBox")).sendKeys("gurutesting"); driver.findElement(By.id("btnLoginAccount_btnLog inAccount_Button")).click(); driver.manage().timeouts().implicitlyWait(20, Ti

meUnit.SECONDS); } @DataProvider(name = "PostProjectData") // Data collecting fro m excel sheet for Post Project public Object[][] getData() { return new Object[][]{ {"projectTitle1", "projectDescription1", "SubscribersOnly", "black-box-testing", "FixedPrice", "10-Nov-2012"}, {"projectTitle2", "projectDescription2", "InvitationOnly", "black-box-testing", "Hourly Rate", "11-Nov-2012"} }; } @Test public static void postProject() throws InterruptedException, AW TException { driver.findElement(By.xpath("//a[@id='ctl00_cntE mp_lnkStartProject']")).click(); driver.manage().timeouts().implicitlyWait(20, Ti meUnit.SECONDS); driver.findElement(By.id("ctl00_cntEmp_ucPostPro ject_txtPT_txtPT_TextBox")).sendKeys("pTitle"); driver.findElement(By.id("ctl00_cntEmp_ucPostPro ject_txtPD_txtPD_TextBox")).sendKeys("pDesc"); // Privacy Option driver.findElement(By.id("privacyCrclIcn")).clic k(); privacyOption = "InvitationOnly"; if(privacyOption=="OpenToAll") { driver.findElement(By.id("checkMark0")). click(); } else if(privacyOption=="SubscribersOnly") { driver.findElement(By.id("checkM ark1")).click(); } else if(privacyOption=="InvitationOnly") { driver.findElement(By.id("checkM ark2")).click(); } else System.out.println("Errro in get ting data"); driver.findElement(By.id("ctl00_cntEmp_ucPostPro ject_btnUpdatePS")).click(); driver.manage().timeouts().implicitlyWait(20, Ti

meUnit.SECONDS); // Add Location driver.findElement(By.id("locationCrclIcn")).cli ck(); driver.findElement(By.id("token-input-ctl00_cntE mp_ucPostProject_txtCountry_txtCountry_TextBox")).sendKeys("India"); Robot robot = new Robot(); robot.keyPress(KeyEvent.VK_ENTER); robot.keyRelease(KeyEvent.VK_ENTER); Thread.sleep(5000); driver.findElement(By.id("ctl00_cntEmp_ucPostPro ject_btnLocation")).click(); Thread.sleep(5000); // Add Industry driver.findElement(By.id("industryCrclIcn")).cli ck(); Select selectBudget1=new Select(driver.findEleme nt(By.id("ctl00_cntEmp_ucPostProject_ddlIndustry_ddlIndustry_Select"))); selectBudget1.selectByVisibleText("Chemicals"); driver.findElement(By.id("ctl00_cntEmp_ucPostPro ject_btnUpdateIndustry")).click(); // Add Desired Skills driver.findElement(By.id("token-input-ctl00_cntE mp_ucPostProject_txtSkills_txtSkills_TextBox")).sendKeys("black-box-testing"); Robot robot1 = new Robot(); robot1.keyPress(KeyEvent.VK_ENTER); robot1.keyRelease(KeyEvent.VK_ENTER); Thread.sleep(10000); projectBudget = "FixedPrice"; if(projectBudget=="FixedPrice"){ Select selectBudget=new Select(driver.fi ndElement(By.id("ctl00_cntEmp_ucPostProject_ddlBudget_ddlBudget_Select"))); selectBudget.selectByVisibleText("Under $250"); }else if(projectBudget=="HourlyRate"){ driver.findElement(By.xpath("//*[@id='ct l00_cntEmp_ucPostProject_rblBudgetType_rblBudgetType_RadioButton_1']")).click(); Select selectBudget2=new Select(driver.f indElement(By.id("ctl00_cntEmp_ucPostProject_ddlDuration_ddlDuration_Select"))); selectBudget2.selectByVisibleText("Less Than 1 Week"); Select selectBudget3=new Select(driver.f indElement(By.id("ctl00_cntEmp_ucPostProject_ddlHrWk_ddlHrWk_Select"))); selectBudget3.selectByVisibleText("As Ne eded Less Than 10 Hours/Week"); driver.findElement(By.id("ctl00_cntEmp_u cPostProject_txtMinRate_txtMinRate_TextBox")).sendKeys("30"); driver.findElement(By.id("ctl00_cntEmp_u

cPostProject_txtMaxRate_txtMaxRate_TextBox")).sendKeys("45"); } // driver.findElement(By.id("ctl00_cntEmp_txtCloseD ate_txtCloseDate_TextBox")).click(); driver.findElement(By.id("ctl00_cntEmp_btnPostPr oject_btnPostProject_Button")).click(); } }

You might also like