예제 #1
0
  /** close all open browsers does not work with Grid */
  public void closeAllBrowsers() {

    // kill all browser procceses
    String username = System.getenv("USERNAME");
    String killExplore = "taskkill /F /FI \"USERNAME eq " + username + "\" /IM IEDriverServer.exe";
    // String killFireFox = "taskkill /F /FI \"USERNAME eq " + username + "\" /IM firefox.exe";
    String killChrome = "taskkill /F /FI \"USERNAME eq " + username + "\" /IM chromedriver.exe";
    // Log.logVerbose("closing all browsers for username: "******"Running: " + killExplore);
      child = Runtime.getRuntime().exec(killExplore);
      child.waitFor();
      // Log.logVerbose("Running: " + killFireFox);
      // child = Runtime.getRuntime().exec(killFireFox);
      // child.waitFor();
      // Log.logVerbose("Running: " + killChrome);
      child = Runtime.getRuntime().exec(killChrome);
      child.waitFor();
    } catch (IOException e) {
    } catch (InterruptedException e) {
    }
  }
  protected WebDriver markForAutoClose(WebDriver webDriver) {
    ALL_WEB_DRIVERS_THREADS.add(currentThread());

    if (!cleanupThreadStarted.get()) {
      synchronized (this) {
        if (!cleanupThreadStarted.get()) {
          new UnusedWebdriversCleanupThread().start();
          cleanupThreadStarted.set(true);
        }
      }
    }
    Runtime.getRuntime()
        .addShutdownHook(new WebdriversFinalCleanupThread(webDriver, currentThread()));
    return webDriver;
  }
예제 #3
0
파일: LFT.java 프로젝트: qarocks/SPW
  @Test
  public void LFTMain() throws Exception {
    JavascriptExecutor js = (JavascriptExecutor) webDriver;
    selenium.open(baseUrl);
    selenium.type("id=id_username", sender);
    selenium.type("id=id_password", "123abc");
    selenium.click("css=input[type=\"submit\"]");

    selenium.waitForPageToLoad("2000");

    System.out.println("First: The page title is " + selenium.getTitle());
    // code to upload file

    driver.findElement(By.linkText("Compose")).click();

    selenium.waitForPageToLoad("3000");

    // Runtime.getRuntime().exec("C:\\Users\\Sneha\\Desktop\\IE.exe");
    Runtime.getRuntime().exec("C:\\Users\\Sneha\\Desktop\\silver_autoit.exe");

    Functions.MyWaitfunc(driver, "//*[@id='uploader_browse']");
    WebElement ele = driver.findElement(By.xpath("//*[@id='uploader_browse']"));
    ele.click();

    // ele.sendKeys("C:\\Users\\Sneha\\Desktop\\Lighthouse.jpg");

    // send secure mail
    // driver.findElement(By.id("secure")).click();

    driver.findElement(By.id("addrin")).sendKeys(recipient);

    driver.findElement(By.id("id_subject")).sendKeys(stringToTest_tc001);

    String torun = "document.getElementById('tinymce').innerHTML='Hi there!'";

    driver.findElement(By.id("addrsubmit")).click();

    /*selenium.waitForPageToLoad("3000");

    		Thread.sleep(100);
    		js.executeScript(torun);

    		System.out.println((String)js.executeScript("return document.title"));

    */

    driver.switchTo().frame("id_body_ifr");

    selenium.typeKeys("//body[@id='tinymce']", "Finally wohoooo!!");
    driver.switchTo().defaultContent();

    driver.findElement(By.id("submitter")).click();

    /* code only if it is LFT

    String per_done="//html/body/div/div[2]/div[4]/form/fieldset/div[9]/div/div/div/div[2]/table[2]/tbody/tr/td[3]/span";
    NoSuchElementException e1 = null;

    // code to wait for file to be uploaded
    for (int second = 0;; second++) {

    	if (second >= 60) {fail("timeout");}
    	try { if (driver.findElement(By.xpath(per_done)).getText().equalsIgnoreCase("548 KB")) break; } catch (Exception e) {}
    	Thread.sleep(1000);


    }
    */
    // mail body

    /* code to run if LFT
    //System.out.println((String)js.
    if((this.doesWebElementExist(driver,By.xpath(per_done))) && (driver.findElement(By.xpath(per_done)).getText().equalsIgnoreCase("548 KB")))

    	{//driver.findElement(By.id("submitter")).click();
    	}

    else
    	throw e1;

    */

    /* this section if confirm dialog pops up!

    this.MyWaitfunc("//html/body/div[4]/div[11]/div/button/span");

          if(driver.findElement(By.xpath("//html/body/div[4]/div[11]/div/button/span")).isDisplayed())

    	driver.findElement(By.xpath("//html/body/div[4]/div[11]/div/button/span")).click();
    else
    	System.out.println("Confirm dialog not up yet!");
    */

    // to check if mail was sent successfully

    String success_str_xpath = "//html/body/div/div[2]/div[3]/ul/li";

    Functions.MyWaitfunc(driver, success_str_xpath);
    if ((Functions.doesWebElementExist(driver, By.xpath(success_str_xpath)))
        && (driver
            .findElement(By.xpath(success_str_xpath))
            .getText()
            .contains("Successfully sent the email")))
      System.out.println("SUCCESS:Mail successfully sent !");
    else {
      System.out.println("FAIL:Mail NOT SENT !");
      System.out.println(driver.findElement(By.xpath(success_str_xpath)).getText());
      Exception e1 = null;
      throw e1;
    }
  }