Advertisement
Guest User

Untitled

a guest
Jul 1st, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.79 KB | None | 0 0
  1. package ua.pp.msk.julia.seleniumlearn;
  2.  
  3. import java.awt.event.InputEvent;
  4. import java.util.concurrent.TimeUnit;
  5. import java.util.logging.Logger;
  6. import org.openqa.selenium.By;
  7. import org.openqa.selenium.JavascriptExecutor;
  8. import org.openqa.selenium.WebDriver;
  9. import org.openqa.selenium.WebElement;
  10. import org.openqa.selenium.firefox.MarionetteDriver;
  11. import org.openqa.selenium.remote.DesiredCapabilities;
  12. import org.openqa.selenium.support.ui.ExpectedCondition;
  13. import org.openqa.selenium.support.ui.WebDriverWait;
  14. import org.openqa.selenium.support.ui.ExpectedConditions;
  15. import org.openqa.selenium.support.ui.Select;
  16.  
  17. public class JiraApp {
  18.  
  19.     public static String url;
  20.     public static WebDriver driver;
  21.  
  22.     public static void main(String[] args) {
  23.  
  24.         System.setProperty("webdriver.gecko.driver", "/opt/selenium/bin/geckodriver-0.8.0-linux64");
  25.         DesiredCapabilities caps = DesiredCapabilities.firefox();
  26.         caps.setCapability("marionette", true);
  27.         // url = args[0];
  28.         url = "http://10.23.144.170:8080/login.jsp";
  29.         WebDriverWait wait = null;
  30.  
  31.         try {
  32.             driver = new MarionetteDriver(4444);
  33.             wait = new WebDriverWait(driver, 120);
  34.  
  35.             driver.get(url);
  36.             System.out.println("URL was loaded SUCESSFULLY");
  37.             //Thread.sleep(7000);
  38.             driver.findElement(By.name("os_username")).sendKeys("ynahorna");
  39.             WebElement password = wait.until(ExpectedConditions.presenceOfElementLocated(By.id("login-form-password")));
  40.             password.sendKeys("ynahorna");
  41.             driver.findElement(By.name("login")).submit();
  42.  
  43.             /*
  44.              Part 1: MAIN functionality of LOE Plug-in
  45.            
  46.              */
  47.             System.out.println("Part 1: MAIN functionality of LOE Plug-in");
  48.  
  49.             /*
  50.              1. Select Project
  51.              2. Add Support Group
  52.              - select company
  53.              - Business
  54.              - Group
  55.              - Contact(search form)
  56.              3. Add Labor
  57.              - Select Company
  58.              - Select Rate class
  59.              - Add month
  60.              4. Add Non Labor
  61.              - Select Category
  62.              - Select Month
  63.              5. Delete Labor Resource
  64.              6. Delete Non Labor Resource
  65.              */
  66.             //Select dropdown = new Select(driver.findElement(By.id("projectMenu")));
  67.             //Robot robot = new Robot();
  68.             waitForLoad(driver);
  69.             String parentWindow = driver.getWindowHandle();
  70.             WebElement iFrame = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("gadget-39829")));
  71.             driver.switchTo().frame("gadget-39829");
  72.             System.err.println("In the iFrame");
  73.             WebElement projectName = wait.until(ExpectedConditions.elementToBeClickable(By.xpath(".//*[@id='projectMenu']")));
  74.             //wait.until(ExpectedConditions.visibilityOf(projectName));
  75.             projectName.click();
  76.             Select projectSelect = new Select(wait.until(ExpectedConditions.elementToBeClickable(By.id("projectMenu"))));
  77.             System.out.println("Number of found options: " + projectSelect.getOptions().size());
  78.             projectSelect = new Select(wait.until(ExpectedConditions.elementToBeClickable(By.id("projectMenu"))));
  79.              projectSelect.selectByIndex(7);
  80.             //projectSelect.selectByVisibleText("10 VIPSC Network Service Management (PRJ-379)");
  81.             //WebElement firstSelectedOption = projectSelect.getFirstSelectedOption();
  82.             //System.out.println(" Selected option " + firstSelectedOption.getText() + " " + firstSelectedOption.isSelected());
  83.             //firstSelectedOption.click();
  84.             projectSelect.getOptions().get(7).click();
  85.            
  86.             //projectName.submit();
  87.            
  88.             wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("exportKeyBtn"))).click();
  89.             //Now Robot usage...
  90.  
  91. //            Thread.sleep(10000);
  92. //            projectSelect.selectByIndex(10);
  93. //            projectName.submit();
  94. //            Thread.sleep(10000);
  95. //            projectSelect.selectByVisibleText("CAMC 2020 - Phase I (PRJ-301)");
  96. //            projectName.submit();
  97. //            //wait.until(ExpectedConditions.elementToBeClickable(projectName)).click();
  98. //            //projectName.click();
  99. //            Thread.sleep(10000);
  100. //            projectName.sendKeys("CDN");
  101. //            projectName.submit();
  102. //            Thread.sleep(10000);
  103.             driver.switchTo().parentFrame();
  104.         } catch (Exception ex) {
  105.             Logger.getLogger("Exception! " + ex.getMessage());
  106.         } finally {
  107.             try {
  108.                 Thread.sleep(60000);
  109.                 if (driver != null) {
  110.                     driver.quit();
  111.                 }
  112.             } catch (InterruptedException ex) {
  113.                 System.err.println("Interrupted quit " + ex.getMessage());
  114.             }
  115.         }
  116.  
  117.     }
  118.  
  119.     static void waitForLoad(WebDriver driver) {
  120.         //  new WebDriverWait(driver, 30).until((ExpectedCondition<Boolean>) wd -> ((JavascriptExecutor) wd).executeScript("return document.readyState").equals("complete"));
  121.         if (driver instanceof MarionetteDriver) {
  122.             new WebDriverWait(driver, 60).until(new ExpectedCondition<Boolean>() {
  123.  
  124.                 @Override
  125.                 public Boolean apply(WebDriver f) {
  126.                     JavascriptExecutor jse = (MarionetteDriver) f;
  127.                     return jse.executeScript("return document.readyState").equals("complete");
  128.                 }
  129.             });
  130.             System.err.println("Page loading complete");
  131.         } else {
  132.             System.err.println("Unsupported class of web driver " + driver.getClass().getCanonicalName());
  133.         }
  134.     }
  135.  
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement