コード例 #1
0
ファイル: Base.java プロジェクト: rashed1/selenium-bootcamp
  @Parameters({"useCloudEnv", "userName", "key", "os", "browser", "browserVersion", "url"})
  @BeforeMethod
  public void setUp(
      @Optional("false") Boolean useCloudEnv,
      @Optional("rashed1") String userName,
      @Optional("2601a7b6-4b39-4712-992a-59ddcd85694c") String key,
      @Optional("Windows 10") String OS,
      @Optional("firefox") String browser,
      @Optional("43.0.1") String browserVersion,
      @Optional("http://www.cigna.com") String url)
      throws IOException {

    if (useCloudEnv == true) {
      // run on cloud
      logger.setLevel(Level.INFO);
      logger.info("Test is running on cloud env");
      getCloudDriver(userName, key, OS, browser, browserVersion);
      System.out.println("Tests is running on Saucelabs, please wait for result");

    } else {
      // run on local
      getLocalDriver(OS, browser, browserVersion);
    }
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    driver.navigate().to(url);
    driver.manage().window().maximize();
  }
コード例 #2
0
  @SuppressWarnings("deprecation")
  @Test
  public void booking() {

    // click to choose book services
    //			driver.findElement(By.xpath(".//*[@id='gt_sr']")).click();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    // Click to choose service
    driver.findElement(By.xpath(Bookingpage.Service)).click();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    // Click to choose staff
    driver.findElement(By.xpath(Bookingpage.Staff1)).click();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    // Click to choose date
    List<WebElement> date = driver.findElements(By.xpath(Bookingpage.TodayDate));

    String selectedDate = date.get(0).getText();
    driver.findElement(By.linkText(selectedDate)).click();

    // List the timeslots
    List<WebElement> availslots = driver.findElements(By.xpath(Bookingpage.Timeslot));
    int bookings = availslots.size();
    System.out.println(" Time slots size :: " + bookings);
    try {
      if (bookings > 0) {
        String[] slots1 = new String[bookings];
        int j = 0;
        // System.out.println(" available slots :: "+availslots);
        for (WebElement avail : availslots) {
          slots1[j] = avail.getText();
          System.out.println(slots1[j]);
          j++;

          for (String SelectedSlot : slots1) {

            System.out.println("Selected SLot :: " + SelectedSlot);
            driver.findElement(By.linkText(SelectedSlot)).click();

            driver.findElement(By.id("cust-IName")).sendKeys("Vimal Tester");

            // Click on continue
            driver.findElement(By.xpath(".//*[@id='cust-continue']")).click();
            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
            // Book My Appointment
            driver.findElement(By.className("global_btn2_rt")).click();
            driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
          }

          break;
        }
      } else {
        System.out.println("slot not available");
      }
    } catch (Exception e) {
      Log.info("Exception " + e.getMessage());
    }
  }
コード例 #3
0
  private void accept(WebDriver driver, String message) {
    StopWatch stopWatch = new Log4JStopWatch();
    stopWatch.start();

    WebElement img = driver.findElement(By.xpath("//img[@alt='Click to sign']"));
    driver.manage().timeouts().implicitlyWait(waitTimeout, TimeUnit.SECONDS);
    img.click();

    List<WebElement> signed_imgs = driver.findElements(By.xpath("//img[@alt='Signed']"));
    driver.manage().timeouts().implicitlyWait(waitTimeout, TimeUnit.SECONDS);

    if (signed_imgs.size() != 0) {
      stopWatch.stop("accept", message);
    } else {
      randomDelay();
      stopWatch.start();
      WebElement awsForm = driver.findElement(By.name("awsForm"));

      driver.manage().timeouts().implicitlyWait(waitTimeout, TimeUnit.SECONDS);
      awsForm.submit();

      signed_imgs = driver.findElements(By.xpath("//img[@alt='Signed']"));
      driver.manage().timeouts().implicitlyWait(waitTimeout, TimeUnit.SECONDS);
      stopWatch.stop("accept'", message);
    }
  }
コード例 #4
0
ファイル: WaitTool.java プロジェクト: sudhakarbetha/Selenium
  /**
   * Wait for the List<WebElement> to be present in the DOM, regardless of being displayed or not.
   * Returns all elements within the current page DOM.
   *
   * @param WebDriver The driver object to be used
   * @param By selector to find the element
   * @param int The time in seconds to wait until returning a failure
   * @return List<WebElement> all elements within the current page DOM, or null (if the timeout is
   *     reached)
   */
  public static List<WebElement> waitForListElementsPresent(
      WebDriver driver, final By by, int timeOutInSeconds) {
    List<WebElement> elements;
    try {
      driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); // nullify implicitlyWait()

      WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
      wait.until(
          (new ExpectedCondition<Boolean>() {
            @Override
            public Boolean apply(WebDriver driverObject) {
              return areElementsPresent(driverObject, by);
            }
          }));

      elements = driver.findElements(by);
      driver
          .manage()
          .timeouts()
          .implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); // reset implicitlyWait
      return elements; // return the element
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }
コード例 #5
0
ファイル: WaitTool.java プロジェクト: sudhakarbetha/Selenium
  /**
   * Wait for an element to appear on the refreshed web-page. And returns the first WebElement using
   * the given method.
   *
   * <p>This method is to deal with dynamic pages.
   *
   * <p>Some sites I have tested required a page refresh to add additional elements to the DOM.
   * Generally you wouldn't need to do this in a typical AJAX scenario.
   *
   * @param WebDriver The driver object to use to perform this element search
   * @param locator selector to find the element
   * @param int The time in seconds to wait until returning a failure
   * @return WebElement the first WebElement using the given method, or null(if the timeout is
   *     reached)
   */
  public static WebElement waitForElementRefresh(
      WebDriver driver, final By by, int timeOutInSeconds) {
    WebElement element;
    try {
      driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); // nullify implicitlyWait()
      new WebDriverWait(driver, timeOutInSeconds) {}.until(
          new ExpectedCondition<Boolean>() {

            @Override
            public Boolean apply(WebDriver driverObject) {
              driverObject.navigate().refresh(); // refresh the page ****************
              return isElementPresentAndDisplay(driverObject, by);
            }
          });
      element = driver.findElement(by);
      driver
          .manage()
          .timeouts()
          .implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); // reset implicitlyWait
      return element; // return the element
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }
コード例 #6
0
  @Test
  public void shouldRetainCookieInfo() {
    server.setGetHandler(EMPTY_CALLBACK);
    goToPage();

    // Added cookie (in a sub-path - allowed)
    Cookie addedCookie =
        new Cookie.Builder("fish", "cod")
            .expiresOn(new Date(System.currentTimeMillis() + 100 * 1000)) // < now + 100sec
            .path("/404")
            .domain("localhost")
            .build();
    driver.manage().addCookie(addedCookie);

    // Search cookie on the root-path and fail to find it
    Cookie retrieved = driver.manage().getCookieNamed("fish");
    assertNull(retrieved);

    // Go to the "/404" sub-path (to find the cookie)
    goToPage("404");
    retrieved = driver.manage().getCookieNamed("fish");
    assertNotNull(retrieved);
    // Check that it all matches
    assertEquals(addedCookie.getName(), retrieved.getName());
    assertEquals(addedCookie.getValue(), retrieved.getValue());
    assertEquals(addedCookie.getExpiry(), retrieved.getExpiry());
    assertEquals(addedCookie.isSecure(), retrieved.isSecure());
    assertEquals(addedCookie.getPath(), retrieved.getPath());
    assertTrue(retrieved.getDomain().contains(addedCookie.getDomain()));
  }
コード例 #7
0
  /** Creates a {@link WebDriver} for each test, then make sure to clean it up at the end. */
  @Provides
  @TestScope
  public WebDriver createWebDriver(TestCleaner cleaner, TestName testName, ElasticTime time)
      throws IOException {
    WebDriver base = createWebDriver(testName);
    Dimension oldSize = base.manage().window().getSize();
    if (oldSize.height < 768 || oldSize.width < 1024) {
      base.manage().window().setSize(new Dimension(1024, 768));
    }

    final EventFiringWebDriver d = new EventFiringWebDriver(base);
    d.register(new SanityChecker());
    d.register(new Scroller());

    try {
      d.manage().timeouts().pageLoadTimeout(time.seconds(30), TimeUnit.MILLISECONDS);
      d.manage().timeouts().implicitlyWait(time.seconds(1), TimeUnit.MILLISECONDS);
    } catch (UnsupportedCommandException e) {
      // sauce labs RemoteWebDriver doesn't support this
      System.out.println(base + " doesn't support page load timeout");
    }
    cleaner.addTask(
        new Statement() {
          @Override
          public void evaluate() throws Throwable {
            d.quit();
          }
        });
    return d;
  }
コード例 #8
0
ファイル: WaitTool.java プロジェクト: sudhakarbetha/Selenium
 /**
  * Reset ImplicitWait. To reset ImplicitWait time you would have to explicitly set it to zero to
  * nullify it before setting it with a new time value.
  */
 public static void resetImplicitWait(WebDriver driver) {
   driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); // nullify implicitlyWait()
   driver
       .manage()
       .timeouts()
       .implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); // reset implicitlyWait
 }
コード例 #9
0
  // chrome
  public void seleniumChrome(String filePath, String url) throws InterruptedException {
    System.out.println(String.format("Fetching %s...", url));

    // 设置
    System.setProperty(
        "webdriver.chrome.driver",
        "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe");
    System.out.println("chromedriver opened");

    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setCapability("chrome.switches", Arrays.asList("--start-maximized"));

    WebDriver driver = new org.openqa.selenium.chrome.ChromeDriver(capabilities);
    driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS); // 5秒内没打开,重新加载
    while (true) {
      try {
        driver.get(url);
      } catch (Exception e) {
        driver.quit();
        driver = new ChromeDriver();
        driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);
        continue;
      }
      break;
    }
    // save page
    String html = driver.getPageSource();
    saveHtml(filePath, html);
    System.out.println("save finish...");
    // Close the browser
    Thread.sleep(2000);
    driver.quit();
  }
コード例 #10
0
ファイル: WaitTool.java プロジェクト: sudhakarbetha/Selenium
 /**
  * Reset ImplicitWait.
  *
  * @param int - a new wait time in seconds
  */
 public static void resetImplicitWait(WebDriver driver, int newWaittime_InSeconds) {
   driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); // nullify implicitlyWait()
   driver
       .manage()
       .timeouts()
       .implicitlyWait(newWaittime_InSeconds, TimeUnit.SECONDS); // reset implicitlyWait
 }
コード例 #11
0
  /**
   * 实现功能:爬取作者页面,输入是 “页面保存路径filepath” 和 “作者页面链接url” 10秒内没打开页面会重开 无需下来页面,所需信息都在页面顶部 使用技术:Selenium
   *
   * @param filePath, url
   */
  public void seleniumCrawlerAuthor(String filePath, String url) throws InterruptedException {
    System.out.println(String.format("Fetching %s...", url));

    // 设置
    //		System.setProperty("webdriver.ie.driver","C:\\Program Files\\Internet
    // Explorer\\IEDriverServer.exe");
    //		System.out.println("InternetExplorerDriver opened");

    WebDriver driver = new InternetExplorerDriver();
    driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS); // 5秒内没打开,重新加载
    while (true) {
      try {
        driver.get(url);
      } catch (Exception e) {
        driver.quit();
        driver = new InternetExplorerDriver();
        driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);
        continue;
      }
      break;
    }
    // save page
    String html = driver.getPageSource();
    saveHtml(filePath, html);
    System.out.println("save finish...");
    // Close the browser
    Thread.sleep(2000);
    driver.quit();
  }
コード例 #12
0
ファイル: WebPageHelpers.java プロジェクト: priteshg/sharpqa
 public static List<WebElement> createWebElementsList(WebDriver driver, By by) {
   List<WebElement> webElements;
   driver.manage().timeouts().implicitlyWait(0, TimeUnit.MILLISECONDS); // Quickly
   webElements = driver.findElements(by);
   driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
   return webElements;
 }
コード例 #13
0
 private void goToTestPage(WebDriver driver) {
   driver.get(baseUrl);
   driver.manage().timeouts().implicitlyWait(waitTimeout, TimeUnit.SECONDS);
   // create/resume transaction
   WebElement createButton = driver.findElement(By.id("resume"));
   driver.manage().timeouts().implicitlyWait(waitTimeout, TimeUnit.SECONDS);
 }
コード例 #14
0
ファイル: WaitTool.java プロジェクト: sudhakarbetha/Selenium
  /**
   * Waits for the completion of Ajax jQuery processing by checking "return jQuery.active == 0"
   * condition.
   *
   * @param WebDriver - The driver object to be used to wait and find the element
   * @param int - The time in seconds to wait until returning a failure
   * @return boolean true or false(condition fail, or if the timeout is reached)
   */
  public static boolean waitForJQueryProcessing(WebDriver driver, int timeOutInSeconds) {
    boolean jQcondition = false;
    try {
      driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); // nullify implicitlyWait()
      new WebDriverWait(driver, timeOutInSeconds) {}.until(
          new ExpectedCondition<Boolean>() {

            @Override
            public Boolean apply(WebDriver driverObject) {
              return (Boolean)
                  ((JavascriptExecutor) driverObject).executeScript("return jQuery.active == 0");
            }
          });
      jQcondition =
          (Boolean) ((JavascriptExecutor) driver).executeScript("return jQuery.active == 0");
      driver
          .manage()
          .timeouts()
          .implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); // reset implicitlyWait
      return jQcondition;
    } catch (Exception e) {
      e.printStackTrace();
    }
    return jQcondition;
  }
コード例 #15
0
 /**
  * 实现功能:爬取主题页面,输入是 “页面保存路径filepath” 和 “主题页面链接url” 下拉四次主题页面,10秒内没打开页面会重开(问题数目为49-59) 调整 下拉次数
  * 可以得到问题数目会 增加 使用技术:Selenium
  *
  * @param filePath, url
  * @throws InterruptedException
  */
 public static void seleniumCrawlerSubject(String filePath, String url)
     throws InterruptedException {
   // 设置
   //		System.setProperty("webdriver.ie.driver","C:\\Program Files\\Internet
   // Explorer\\IEDriverServer.exe");
   //		System.out.println("InternetExplorerDriver opened");
   File file = new File(filePath);
   int delay = 12;
   if (!file.exists()) {
     //			try{
     //
     //			} catch(Exception e) {
     //
     //			}
     WebDriver driver = new InternetExplorerDriver();
     // 5秒内没打开,重新加载
     driver.manage().timeouts().pageLoadTimeout(delay, TimeUnit.SECONDS);
     while (true) {
       try {
         driver.get(url);
       } catch (Exception e) {
         driver.quit();
         driver = new InternetExplorerDriver();
         driver.manage().timeouts().pageLoadTimeout(delay, TimeUnit.SECONDS);
         continue;
       }
       break;
     }
     System.out.println("Page title is: " + driver.getTitle());
     // roll the page
     JavascriptExecutor JS = (JavascriptExecutor) driver;
     try {
       JS.executeScript("scrollTo(0, 5000)");
       System.out.println("1");
       Thread.sleep(5000); // 调整休眠时间可以获取更多的内容
       JS.executeScript("scrollTo(5000, 10000)");
       System.out.println("2");
       Thread.sleep(5000);
       JS.executeScript("scrollTo(10000, 30000)"); // document.body.scrollHeight
       System.out.println("3");
       Thread.sleep(5000);
       JS.executeScript("scrollTo(10000, 80000)"); // document.body.scrollHeight
       System.out.println("4");
       Thread.sleep(5000);
     } catch (Exception e) {
       System.out.println("Error at loading the page ...");
       driver.quit();
     }
     // save page
     String html = driver.getPageSource();
     saveHtml(filePath, html);
     System.out.println("save finish");
     // Close the browser
     Thread.sleep(2000);
     driver.quit();
   } else {
     System.out.println(filePath + "已经存在,不必再次爬取...");
   }
 }
  /** Constructor to initialize the driver setting */
  public SeleniumHelper() {

    _driver = new Driver().getDriver();
    _driver.manage().window().maximize();
    _driver.manage().timeouts().implicitlyWait(_IMPLICIT_TIMEOUT, TimeUnit.SECONDS);
    _driver.manage().timeouts().pageLoadTimeout(_PAGE_LOAD_TIMEOUT, TimeUnit.SECONDS);
    _wait = new WebDriverWait(_driver, 60);
  }
コード例 #17
0
  public static List<WebElement> findElementsWithTimeout(
      WebDriver driver, int timeoutSeconds, By by) {
    driver.manage().timeouts().implicitlyWait(timeoutSeconds, TimeUnit.SECONDS);
    List<WebElement> foundElements = driver.findElements(by);
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

    return foundElements;
  }
コード例 #18
0
 @Override
 public void reserveWindowRect(String testStepNo) {
   if (windowSizeCheckNoSet.contains(testStepNo)) {
     log.debug("ウィンドウ位置、サイズを取得します");
     Point winPos = seleniumDriver.manage().window().getPosition();
     Dimension winSize = seleniumDriver.manage().window().getSize();
     current.setWindowRect(winPos.getX(), winPos.getY(), winSize.getWidth(), winSize.getHeight());
   }
 }
コード例 #19
0
	public static void main(String[] args) {
	 
		WebDriver driver = new FirefoxDriver();
		driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
        driver.manage().window().maximize();
        driver.get("http://bachecalloggi.listedisinistra.org/index.php/annunci");
        driver.findElement(By.xpath("//button[contains(text(),'Ricerca Avanzata')]")).click();
        select1(driver);
	}
コード例 #20
0
  public static void main(String[] args) {
    WebDriver driver = new FirefoxDriver();
    driver.get("http://www.hsh.com/");
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    driver.findElement(By.xpath("//*[@id='hpRightCol']/div[5]/div/div/a")).click();
    driver.manage().timeouts().implicitlyWait(7, TimeUnit.SECONDS);
    System.out.println(driver.getTitle());
    Assert.assertNotEquals("", "", driver.getTitle());
  }
コード例 #21
0
  @Before
  public void setUp() {
    driver = new FirefoxDriver();
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    driver.manage().window().maximize();

    driver.get("https://alpha-external.pay.naver.com/npoint/pay/charge.nhn?CHNL=NV#");
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

    // 일반 로그인
    driver.findElement(By.id("id")).sendKeys("nvqa_bill111");
    driver.findElement(By.id("pw")).sendKeys("btest789");
    driver.findElement(By.cssSelector("input.int_jogin")).click();

    // 사파리 진입 시, 알럿확인
    try {
      Alert alert = driver.switchTo().alert();
      // String textOnAlert = alert.getText();
      alert.accept();

      // assertEquals("계좌이체 및 신용카드포인트 결제는 IE에서 가능합니다.", textOnAlert);
    } catch (NoAlertPresentException e) {
      e.printStackTrace();
    }

    // 확인해주세요 팝업 확인

    /*	String parentWindowId = driver.getWindowHandle();

    		Set<String> allWindows = driver.getWindowHandles();
    		if (!allWindows.isEmpty()) {
    			for (String windowID : allWindows) {
    				driver.switchTo().window(windowID);
    				if (driver.getPageSource().contains("확인해 주세요.")) {
    					try {
    						WebElement noMoreButton = driver
    								.findElement(By
    										.xpath("//*[@id='infoPopupNGCASH']/div/p/span"));
    						noMoreButton.click();

    						WebElement identifyButton = driver
    								.findElement(By
    										.xpath("//*[@id='infoPopupNGCASH']/div/p/a/img"));
    						identifyButton.click();
    						break;
    					} catch (NoSuchWindowException e) {
    						e.printStackTrace();
    					}
    				}
    			}
    		}

    		driver.switchTo().window(parentWindowId);
    */
  }
コード例 #22
0
  private void submit(WebDriver driver) {
    WebElement submitButton = driver.findElement(By.name("button"));
    driver.manage().timeouts().implicitlyWait(waitTimeout, TimeUnit.SECONDS);

    submitButton.click();

    WebElement awsForm = driver.findElement(By.name("awsForm"));
    //		System.out.println(awsForm.toString());
    driver.manage().timeouts().implicitlyWait(waitTimeout, TimeUnit.SECONDS);
    awsForm.submit();
  }
コード例 #23
0
 protected void driverSettings() {
   driver
       .manage()
       .timeouts()
       .implicitlyWait(WaitUtils.IMPLICIT_ELEMENT_WAIT_MILLIS, TimeUnit.MILLISECONDS);
   driver
       .manage()
       .timeouts()
       .pageLoadTimeout(WaitUtils.PAGELOAD_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
   driver.manage().window().maximize();
 }
コード例 #24
0
  @Test
  public void manipulateWindowSize() {
    WebDriver d = getDriver();

    d.get("http://www.google.com");
    assertTrue(d.manage().window().getSize().width > 100);
    assertTrue(d.manage().window().getSize().height > 100);

    d.manage().window().setSize(new Dimension(1024, 768));
    assertEquals(d.manage().window().getSize().width, 1024);
    assertEquals(d.manage().window().getSize().height, 768);
  }
コード例 #25
0
  @Test
  public void manipulateWindowPosition() {
    WebDriver d = getDriver();

    d.get("http://www.google.com");
    assertTrue(d.manage().window().getPosition().x >= 0);
    assertTrue(d.manage().window().getPosition().y >= 0);

    d.manage().window().setPosition(new Point(0, 0));
    assertTrue(d.manage().window().getPosition().x == 0);
    assertTrue(d.manage().window().getPosition().y == 0);
  }
コード例 #26
0
ファイル: Products.java プロジェクト: ew9001/BrandProduction
  @Test(priority = 1)
  public void registerPage() throws IOException, InterruptedException {
    name = "" + folder + "/" + brand + "_" + browser + "_" + "expanded_menu.png";
    System.out.println("Let me take screenshot");
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

    takeScreenshot(name);
  }
コード例 #27
0
ファイル: OpenBrowser.java プロジェクト: PratyushJaiswal/Test
 // @before annotations Describes this method has to run before the all suite
 @BeforeSuite
 public void openSite()
     throws
         Exception { // There are chances that below code can generate some exception to handle
                     // that used throws
   driver.manage().window().maximize(); // Codes make sure that the browser is always in maximized
   driver
       .manage()
       .timeouts()
       .implicitlyWait(
           15, TimeUnit.SECONDS); // This code will wait for the 15 seconds for opening the get Url
   driver.get("http://aimstaging.entrustenergy.com/standard");
 }
コード例 #28
0
  @Test
  public void manipulateWindowMaximize() {
    WebDriver d = getDriver();

    d.get("http://www.google.com");

    Dimension sizeBefore = d.manage().window().getSize();
    d.manage().window().maximize();
    Dimension sizeAfter = d.manage().window().getSize();

    assertTrue(sizeBefore.width <= sizeAfter.width);
    assertTrue(sizeBefore.height <= sizeAfter.height);
  }
コード例 #29
0
 protected WebDriver maximize(WebDriver driver) {
   if (startMaximized) {
     try {
       if (isChrome()) {
         maximizeChromeBrowser(driver.manage().window());
       } else {
         driver.manage().window().maximize();
       }
     } catch (Exception cannotMaximize) {
       log.warning("Cannot maximize " + browser + ": " + cannotMaximize);
     }
   }
   return driver;
 }
コード例 #30
0
 public void openBrowser() {
   if (prop.getProperty("browser").equals("Firefox")) {
     driver = new FirefoxDriver();
   } else if (prop.getProperty("browser").equals("Chrome")) {
     System.setProperty("webdriver.chrome.driver", "C:\\Jars\\chromedriver.exe");
     driver = new ChromeDriver();
   } else if (prop.getProperty("browser").equals("InternetExplorer")) {
     System.setProperty("webdriver.ie.driver", "C:\\Jars\\IEDriverServer.exe");
     driver = new InternetExplorerDriver();
   }
   driver.manage().window().maximize();
   driver.manage().timeouts().implicitlyWait(30L, TimeUnit.SECONDS);
   driver.manage().timeouts().pageLoadTimeout(30L, TimeUnit.SECONDS);
 }