Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import io.github.bonigarcia.wdm.WebDriverManager;
- import org.openqa.selenium.*;
- import org.openqa.selenium.chrome.ChromeDriver;
- import org.openqa.selenium.support.ui.ExpectedCondition;
- import org.openqa.selenium.support.ui.ExpectedConditions;
- import org.openqa.selenium.support.ui.WebDriverWait;
- import org.testng.Assert;
- import org.testng.annotations.AfterTest;
- import org.testng.annotations.BeforeTest;
- import org.testng.annotations.Test;
- import io.github.bonigarcia.wdm.WebDriverManager;
- import org.openqa.selenium.*;
- import org.openqa.selenium.chrome.ChromeDriver;
- import org.testng.annotations.AfterTest;
- import org.testng.annotations.BeforeTest;
- import org.testng.annotations.Test;
- import java.util.concurrent.TimeUnit;
- import java.util.concurrent.TimeUnit;
- public class Explicit {
- WebDriver driver;
- @BeforeTest
- public void setUp() {
- WebDriverManager.chromedriver().setup();
- this.driver = new ChromeDriver();
- }
- @Test
- public void firstTestLoginToJira() throws InterruptedException {
- // Fix for - The path to the driver executable must be set by the webdriver.chrome.driver system property
- // System.setProperty("webdriver.chrome.driver", "D:\\QA_Auto\\12345\\chromedriver.exe");
- // Create a new instance of the Firefox driver
- // WebDriver driver = new ChromeDriver();
- driver.get("https://jira.hillel.it/login.jsp");
- driver.findElement(By.xpath("//input[@name='os_username']")).sendKeys("webinar5");
- driver.findElement(By.xpath("//input[@name='os_password']")).sendKeys("webinar5");
- driver.findElement(By.xpath("//input[@name='login']")).click();
- Assert.assertEquals(driver.getCurrentUrl(), "https://jira.hillel.it/secure/Dashboard.jspa");
- //Thread.sleep(50000);
- WebDriverWait wait = new WebDriverWait(driver, 20);//Заменила Thread.sleep() на explicit wait
- wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[@id='create_link']")));
- driver.findElement(By.xpath("//a[@id='create_link']")).click();
- //Thread.sleep(30000);
- //WebElement element1 =
- WebDriverWait wait1 = new WebDriverWait(driver, 20);//Заменила Thread.sleep() на explicit wait
- wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@id='project-field']")));
- //driver.findElement(By.xpath("//input[@id='project-field']"));
- //driver.findElement(By.xpath("//input[@id='project-field']")).clear();//QAAUTO-8(QAAUT-8) выбираем
- //driver.findElement(By.xpath("//input[@id='project-field']")).sendKeys("QAAUTO-8 (QAAUT8)");
- //driver.findElement(By.xpath("//div[@class='qf-container']")).click();
- //заменяем предыдуший код на enterText
- enterText(By.xpath("//input[@id='project-field']"), "Test", 3, 10);
- enterText(By.xpath("//input[@id='issuetype-field']"), "QAAUTO-8", 3, 10);
- //driver.findElement(By.xpath("//input[@id='issuetype-field']"));
- //driver.findElement(By.xpath("//input[@id='issuetype-field']")).clear();
- //driver.findElement(By.xpath("//input[@id='issuetype-field']")).sendKeys("Task");
- //driver.findElement(By.xpath("//div[@class='qf-container']")).click();
- //driver.findElement(By.xpath("//input[@id='summary']")).sendKeys("THIS IS TEST FOR QA AUTOMATION");
- //driver.findElement(By.xpath("//textarea[@id='description']")).sendKeys("THIS IS TEST FOR QA AUTOMATION in Jira");
- enterText(By.xpath("//input[@id='summary']"), "This is an automatic test.", 3, 10);
- enterText(By.xpath("//textarea[@id='description']"), "This is an automatic test.", 3, 10);
- //Thread.sleep(30000);
- WebDriverWait wait2 = new WebDriverWait(driver, 20);//Заменила Thread.sleep() на explicit wait
- wait2.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@id='create-issue-submit']")));
- driver.findElement(By.xpath("//input[@id='create-issue-submit']")).click();
- //Thread.sleep(2000);
- //assertTrue(true,"has been successfully created");
- //assertTrue(driver.findElement( By.xpath("//div[@class='aui-message closeable aui-message-success aui-will-close']")).isDisplayed());
- driver.quit();
- }
- private WebElement sendKeys(By element, int retry, int timeoutSeconds) {
- for (int i = retry; i > 0; i--) {
- try {
- driver.findElement(element);
- } catch (Exception ex) {
- try {
- Thread.sleep(TimeUnit.SECONDS.toMillis(timeoutSeconds));
- driver.findElement(element);
- } catch (Exception ex2) {
- System.out.println("Searching element" + element.toString() + ". Retry - " + (retry - i));
- continue;
- }
- }
- return driver.findElement(element);
- }
- return driver.findElement(element);
- }
- private void click(By element, int retry, int timeoutSeconds) {
- for (int i = retry; i > 0; i--) {
- try {
- System.out.println("Searching element" + element.toString() + ". Retry - " + (retry - i));
- driver.findElement(element).click();
- break;
- } catch (NoSuchElementException | StaleElementReferenceException | ElementNotInteractableException ex) {
- try {
- System.out.println("Searching element" + element.toString() + ". Retry - " + (retry - i));
- Thread.sleep(TimeUnit.SECONDS.toMillis(timeoutSeconds));
- driver.findElement(element).click();
- break;
- } catch (NoSuchElementException | StaleElementReferenceException | ElementNotInteractableException | InterruptedException ex2) {
- continue;
- }
- }
- }
- }
- private void enterText(By element, String text, int retry, int timeoutSeconds) {
- for (int i = retry; i > 0; i--) {
- try {
- System.out.println("Searching element" + element.toString() + ". Retry - " + (retry - i));
- driver.findElement(element).sendKeys(text);
- break;
- } catch (NoSuchElementException | StaleElementReferenceException | ElementNotInteractableException ex) {
- try {
- System.out.println("Searching element" + element.toString() + ". Retry - " + (retry - i));
- Thread.sleep(TimeUnit.SECONDS.toMillis(timeoutSeconds));
- driver.findElement(element).sendKeys(text);
- break;
- } catch (NoSuchElementException | StaleElementReferenceException | ElementNotInteractableException | InterruptedException ex2) {
- continue;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement