Untitled
unknown
plain_text
a year ago
5.1 kB
8
Indexable
Never
package selenium; import java.util.Random; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; public class Topic_07_Textbox_TextArea { WebDriver driver; String firstNameText, middleNameText, lastNameText, userNameText, passWordText, employerId, numberText, commentText; @BeforeClass public void beforeClass() { System.setProperty("webdriver.gecko.driver", ".\\lib\\geckodriver.exe"); driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); // New user firstNameText = "Auto"; middleNameText = "mation"; lastNameText = "Tester"; userNameText = "luuph" + random(); passWordText = "Aa@123456"; numberText = "1234-456-789"; commentText = "Test Automation"; } @Test public void TC_01_CreatNewAccount() throws InterruptedException { By firstNameTextbox = By.xpath("//input[@name='firstName']"); By middleNameTextbox = By.xpath("//input[@name='middleName']"); By lastNameTextbox = By.xpath("//input[@name='lastName']"); By employerIdTextbox = By.xpath("//label[text()='Employee Id']/parent::div/following-sibling::div/input[@class='oxd-input oxd-input--active']"); By userNameTextbox = By.xpath("//label[text()='Username']/parent::div/following-sibling::div/input[@class='oxd-input oxd-input--active']"); By passwordTextbox = By.xpath("//label[text()='Password']/parent::div/following-sibling::div/input[@class='oxd-input oxd-input--active']"); By rePasswordTextbox = By.xpath("//label[contains(text(), 'Confirm Password')]/parent::div/following-sibling::div/input[@class='oxd-input oxd-input--active']"); By saveBtn = By.xpath("//button[@class='oxd-button oxd-button--medium oxd-button--secondary orangehrm-left-space']"); By numberTextbox = By.xpath("//label[contains(text(),'Number')]/parent::div/following-sibling::div/input[@class='oxd-input oxd-input--active']"); By commentTextbox = By.xpath("//textarea[@placeholder='Type Comments here']"); // Access to Orange HRM driver.get("https://opensource-demo.orangehrmlive.com/web/index.php/auth/login"); driver.findElement(By.xpath("//input[@name='username']")).sendKeys("Admin"); driver.findElement(By.xpath("//input[@name='password']")).sendKeys("admin123"); driver.findElement(By.xpath("//button[@type='submit']")).click(); Thread.sleep(3000); driver.findElement(By.xpath("//span[text()='PIM']")).click(); driver.findElement(By.xpath("//a[text()='Add Employee']")).click(); Thread.sleep(3000); // Input Employer Full Name driver.findElement(firstNameTextbox).sendKeys(firstNameText); driver.findElement(middleNameTextbox).sendKeys(middleNameText); driver.findElement(lastNameTextbox).sendKeys(lastNameText); // Switch to turn on create new user driver.findElement(By.xpath("//span[@class='oxd-switch-input oxd-switch-input--active --label-right']")).click(); // Get EmployerID employerId = driver.findElement(employerIdTextbox).getText(); System.out.println("EmployerID la: " + employerId); // Input username, password driver.findElement(userNameTextbox).sendKeys(userNameText); driver.findElement(passwordTextbox).sendKeys(passWordText); driver.findElement(rePasswordTextbox).sendKeys(passWordText); driver.findElement(saveBtn).click(); // Step 7: Verify data input /* * Assert.assertEquals(driver.findElement(firstNameTextbox).getText(), * firstNameText); * * Assert.assertEquals(driver.findElement(firstNameTextbox).getText(), * middleNameText); * * Assert.assertEquals(driver.findElement(firstNameTextbox).getText(), * lastNameText); * * Assert.assertEquals(driver.findElement(employerIdTextbox).getText(), * employerId); * */ // Step 8: Click on Immigration Thread.sleep(3000); driver.findElement(By.xpath("//a[@class='orangehrm-tabs-item' and text()='Immigration']")).click(); // Step 9: Assigned Immigration Records. driver.findElement(By.xpath("//h6[text()='Assigned Immigration Records']/parent::div/button[@class='oxd-button oxd-button--medium oxd-button--text']")).click(); // Step 10: Input Number/ Comment, Save Thread.sleep(3000); driver.findElement(numberTextbox).sendKeys(numberText); driver.findElement(commentTextbox).sendKeys(commentText); driver.findElement(By.xpath("//button[@type='submit']")).click(); } @Test public void TC_02_CheckTitle() { String homePageTitle = driver.getTitle(); Assert.assertEquals(homePageTitle, "OrangeHRM"); } // @Test public void TC_03_Homepage_logo_Displayed() { WebElement homePageLogo = driver.findElement(By.xpath("//img[contains(@src,'logo.png')]")); Assert.assertTrue(homePageLogo.isDisplayed()); } public int random() { Random random = new Random(); return random.nextInt(999999); } @AfterClass public void afterClass() { driver.quit(); } }