Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ua.pp.msk.julia.seleniumlearn;
- import java.awt.event.InputEvent;
- import java.util.concurrent.TimeUnit;
- import java.util.logging.Logger;
- import org.openqa.selenium.By;
- import org.openqa.selenium.JavascriptExecutor;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.firefox.MarionetteDriver;
- import org.openqa.selenium.remote.DesiredCapabilities;
- import org.openqa.selenium.support.ui.ExpectedCondition;
- import org.openqa.selenium.support.ui.WebDriverWait;
- import org.openqa.selenium.support.ui.ExpectedConditions;
- import org.openqa.selenium.support.ui.Select;
- public class JiraApp {
- public static String url;
- public static WebDriver driver;
- public static void main(String[] args) {
- System.setProperty("webdriver.gecko.driver", "/opt/selenium/bin/geckodriver-0.8.0-linux64");
- DesiredCapabilities caps = DesiredCapabilities.firefox();
- caps.setCapability("marionette", true);
- // url = args[0];
- url = "http://10.23.144.170:8080/login.jsp";
- WebDriverWait wait = null;
- try {
- driver = new MarionetteDriver(4444);
- wait = new WebDriverWait(driver, 120);
- driver.get(url);
- System.out.println("URL was loaded SUCESSFULLY");
- //Thread.sleep(7000);
- driver.findElement(By.name("os_username")).sendKeys("ynahorna");
- WebElement password = wait.until(ExpectedConditions.presenceOfElementLocated(By.id("login-form-password")));
- password.sendKeys("ynahorna");
- driver.findElement(By.name("login")).submit();
- /*
- Part 1: MAIN functionality of LOE Plug-in
- */
- System.out.println("Part 1: MAIN functionality of LOE Plug-in");
- /*
- 1. Select Project
- 2. Add Support Group
- - select company
- - Business
- - Group
- - Contact(search form)
- 3. Add Labor
- - Select Company
- - Select Rate class
- - Add month
- 4. Add Non Labor
- - Select Category
- - Select Month
- 5. Delete Labor Resource
- 6. Delete Non Labor Resource
- */
- //Select dropdown = new Select(driver.findElement(By.id("projectMenu")));
- //Robot robot = new Robot();
- waitForLoad(driver);
- String parentWindow = driver.getWindowHandle();
- WebElement iFrame = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("gadget-39829")));
- driver.switchTo().frame("gadget-39829");
- System.err.println("In the iFrame");
- WebElement projectName = wait.until(ExpectedConditions.elementToBeClickable(By.xpath(".//*[@id='projectMenu']")));
- //wait.until(ExpectedConditions.visibilityOf(projectName));
- projectName.click();
- Select projectSelect = new Select(wait.until(ExpectedConditions.elementToBeClickable(By.id("projectMenu"))));
- System.out.println("Number of found options: " + projectSelect.getOptions().size());
- projectSelect = new Select(wait.until(ExpectedConditions.elementToBeClickable(By.id("projectMenu"))));
- projectSelect.selectByIndex(7);
- //projectSelect.selectByVisibleText("10 VIPSC Network Service Management (PRJ-379)");
- //WebElement firstSelectedOption = projectSelect.getFirstSelectedOption();
- //System.out.println(" Selected option " + firstSelectedOption.getText() + " " + firstSelectedOption.isSelected());
- //firstSelectedOption.click();
- projectSelect.getOptions().get(7).click();
- //projectName.submit();
- wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("exportKeyBtn"))).click();
- //Now Robot usage...
- // Thread.sleep(10000);
- // projectSelect.selectByIndex(10);
- // projectName.submit();
- // Thread.sleep(10000);
- // projectSelect.selectByVisibleText("CAMC 2020 - Phase I (PRJ-301)");
- // projectName.submit();
- // //wait.until(ExpectedConditions.elementToBeClickable(projectName)).click();
- // //projectName.click();
- // Thread.sleep(10000);
- // projectName.sendKeys("CDN");
- // projectName.submit();
- // Thread.sleep(10000);
- driver.switchTo().parentFrame();
- } catch (Exception ex) {
- Logger.getLogger("Exception! " + ex.getMessage());
- } finally {
- try {
- Thread.sleep(60000);
- if (driver != null) {
- driver.quit();
- }
- } catch (InterruptedException ex) {
- System.err.println("Interrupted quit " + ex.getMessage());
- }
- }
- }
- static void waitForLoad(WebDriver driver) {
- // new WebDriverWait(driver, 30).until((ExpectedCondition<Boolean>) wd -> ((JavascriptExecutor) wd).executeScript("return document.readyState").equals("complete"));
- if (driver instanceof MarionetteDriver) {
- new WebDriverWait(driver, 60).until(new ExpectedCondition<Boolean>() {
- @Override
- public Boolean apply(WebDriver f) {
- JavascriptExecutor jse = (MarionetteDriver) f;
- return jse.executeScript("return document.readyState").equals("complete");
- }
- });
- System.err.println("Page loading complete");
- } else {
- System.err.println("Unsupported class of web driver " + driver.getClass().getCanonicalName());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement