org.openqa.selenium.WebDriver.close()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(5.0k)|赞(0)|评价(0)|浏览(148)

本文整理了Java中org.openqa.selenium.WebDriver.close()方法的一些代码示例,展示了WebDriver.close()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebDriver.close()方法的具体详情如下:
包路径:org.openqa.selenium.WebDriver
类名称:WebDriver
方法名:close

WebDriver.close介绍

[英]Close the current window, quitting the browser if it's the last window currently open.
[中]关闭当前窗口,如果它是当前打开的最后一个窗口,则退出浏览器。

代码示例

代码示例来源:origin: stackoverflow.com

File scrFile = ( (TakesScreenshot) driver ).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File(RESULT_FILENAME));
driver.close();
p.destroy();

代码示例来源:origin: selenide/selenide

private void closeNewWindows(WebDriver webDriver, String currentWindowHandle, Set<String> currentWindows) {
 Set<String> windowHandles = webDriver.getWindowHandles();
 if (windowHandles.size() != currentWindows.size()) {
  Set<String> newWindows = new HashSet<>(windowHandles);
  newWindows.removeAll(currentWindows);
  log.info("File has been opened in a new window, let's close " + newWindows.size() + " new windows");
  for (String newWindow : newWindows) {
   log.info("  Let's close " + newWindow);
   try {
    webDriver.switchTo().window(newWindow);
    webDriver.close();
   }
   catch (NoSuchWindowException windowHasBeenClosedMeanwhile) {
    log.info("  Failed to close " + newWindow + ": " + Cleanup.of.webdriverExceptionMessage(windowHasBeenClosedMeanwhile));
   }
   catch (Exception e) {
    log.warning("  Failed to close " + newWindow + ": " + e);
   }
  }
  webDriver.switchTo().window(currentWindowHandle);
 }
}

代码示例来源:origin: spring-io/initializr

@AfterEach
public void destroy() {
  if (this.driver != null) {
    this.driver.close();
  }
}

代码示例来源:origin: TEAMMATES/teammates

/**
 * Closes the current browser window and switches back to the last window used previously.
 */
public void closeCurrentWindowAndSwitchToParentWindow() {
  driver.close();
  driver.switchTo().window(windowHandles.pop());
}

代码示例来源:origin: org.finra.jtaf/jtaf-extwebdriver

@Override
public void closeCurrentBrowser() {
  wd.close();
  lastSelectedFrame = null;
}

代码示例来源:origin: org.seleniumhq.webdriver/webdriver-selenium

/**
 * Simulates the user clicking the "close" button in the titlebar of a popup
 * window or tab.
 */
public void close() {
 driver.close();
}

代码示例来源:origin: com.github.bordertech.wcomponents/wcomponents-test-lib

/**
 * {@inheritDoc}.
 */
@Override
public void close() {
  driver.close();
}

代码示例来源:origin: com.wso2telco.test/uitest-framework

@Override
public void close() {
  // TODO Auto-generated method stub
  driver.close();
}

代码示例来源:origin: org.paxml/PaxmlSelenium

public static void closeSessions(boolean force) {
  List<WebDriverWrapper> list = getWebDrivers();
  for (int i = list.size() - 1; i >= 0; i--) {
    WebDriverWrapper wp = list.get(i);
    if (force || !wp.keepOnError) {
      wp.webDriver.close();
    }
    list.remove(i);
  }
}

代码示例来源:origin: org.seleniumhq.selenium.server/selenium-server-coreless

public ResultType call() throws Exception {
 WebDriver driver = getDriver();
 driver.close();
 return ResultType.SUCCESS;
}

代码示例来源:origin: com.github.bordertech.webfriends/webfriends-selenium

/**
 * Close the current window.
 */
public void close() {
  getWebDriver().close();
}

代码示例来源:origin: gradle.plugin.GoBqa/gradle-plugin

public static void StopService() throws InterruptedException {
  if (webdriver != null) {
    // long millisecs=10000;
    // Thread.sleep(millisecs);
    webdriver.close();
    webdriver.quit();
  }
  webdriver = null;
}

代码示例来源:origin: net.thucydides/thucydides-core

private void closeSafely(WebDriver driver) {
  try {
    driver.close();
    driver.quit();
  } catch(Throwable ignored) {}
}

代码示例来源:origin: net.serenity-bdd/core

private void closeSafely(WebDriver driver) {
  try {
    driver.close();
    driver.quit();
  } catch(Throwable ignored) {}
}

代码示例来源:origin: org.teavm/teavm-junit

@Override
public void afterThread() {
  webDriver.get().close();
  webDriver.get().quit();
  webDriver.remove();
}

代码示例来源:origin: org.rapidpm/testbench-ng-m-webdriver

@Override
 public void afterEach(ExtensionContext context) throws Exception {
  logger().info("afterEach  -> will close and remove the webdriver now..");
  webdriver()
    .apply(context)
    .close();
  removeWebDriver().accept(context);
 }
}

代码示例来源:origin: com.github.webdriverextensions/webdriverextensions

public static void executeForLink(WebElement link, Runnable function) {
  // Open link in new tab and execute code when in this tab
  String oldWindowHandle = openInNewTabAndFocus(link);
  function.run();
  driver().close();
  driver().switchTo().window(oldWindowHandle);
}

代码示例来源:origin: GluuFederation/oxAuth

private void stopWebDriver(boolean useNewDriver, WebDriver currentDriver) {
  if (useNewDriver) {
    currentDriver.close();
    currentDriver.quit();
  } else {
    stopSelenium();
  }
}

代码示例来源:origin: net.thucydides/thucydides-core

public void close() {
  if (proxyInstanciated()) {
    //if there is only one window closing it means quitting the web driver
    if (getDriverInstance().getWindowHandles() != null && getDriverInstance().getWindowHandles().size() == 1){
      this.quit();
    } else{
      getDriverInstance().close();
    }
    webDriverFactory.shutdownFixtureServices();
  }
}

代码示例来源:origin: net.serenity-bdd/core

public void close() {
  if (proxyInstanciated()) {
    //if there is only one window closing it means quitting the web driver
    if (getDriverInstance().getWindowHandles() != null && getDriverInstance().getWindowHandles().size() == 1){
      this.quit();
    } else{
      getDriverInstance().close();
    }
    webDriverFactory.shutdownFixtureServices();
  }
}

相关文章