TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

Selenium

window .maximize() , .close() and .quit()

In this article we will see sample selenium webdriver programs to maximize window. Difference between .close() and quit() functions.

Browser window  .maximize()

import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 

public class MaximizeWindow { 

 public static void main(String args[])
{ 
 
 WebDriver driver = new FirefoxDriver(); 
 
 driver.get("https://www.bing.com"); 
 
 driver.manage().window().maximize(); 
 
 //testingdocs comment : maximize browser window
 
} 

}

 

Difference between .close() and .quit()

driver.close() : this method closes the browser window that the driver has focus on.

driver.quit(): this method calls dispose

driver.dispose() : closes all browser windows opened by driver instance.and safely ends the session gracefully.

Let see sample programs run in BrowserStack cloud demonstrating the difference between the 2 methods.

Code Listing

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver; 


public class CloseAndQuit { 
 
 public static final String USERNAME="your_BROWSERSTACK_USERNAME";
 public static final String AUTOMATE_KEY = "YOUR_KEY";
 public static final String URL = "https://" + USERNAME + 
":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub";

 
 public static void main(String[] args) throws MalformedURLException 
 { 
 DesiredCapabilities caps = new DesiredCapabilities();
 caps.setCapability("browser", "Firefox");
 caps.setCapability("browser_version", "45");
 caps.setCapability("os", "Windows");
 caps.setCapability("os_version", "10");
 caps.setCapability("browserstack.debug", "true");
 WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
 driver.get("http://www.testingdocs.com");
 driver.manage().window().maximize();
 driver.manage().timeouts().implicitlyWait(30, 
TimeUnit.SECONDS);
 
 WebElement element =driver.
findElement(By.partialLinkText("CONTACT"));
 Actions action=new Actions(driver);
 action.contextClick(element).perform();
 action.sendKeys("w").perform();

 
 // browser window close
 driver.close();

} 

}

 

Quit will close all browser instances :
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class BrowserStackCloseAndQuit 
{
 
 public static final String USERNAME = "your_username";
 public static final String AUTOMATE_KEY = "yourKey";
 public static final String URL = "https://" + USERNAME + 
":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub";

 
public static void main(String[] args) throws 
MalformedURLException, InterruptedException 
{ 
 DesiredCapabilities caps = new DesiredCapabilities();
 caps.setCapability("browser", "Firefox");
 caps.setCapability("browser_version", "45");
 caps.setCapability("os", "Windows");
 caps.setCapability("os_version", "10");
 caps.setCapability("browserstack.debug", "true");
 WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
 driver.get("http://www.testingdocs.com");
 driver.manage().window().maximize();
 driver.manage().timeouts().
implicitlyWait(30, TimeUnit.SECONDS);
 WebElement element =driver.
findElement(By.partialLinkText("CONTACT"));
 Actions action=new Actions(driver);
 action.contextClick(element).perform();
 action.sendKeys("w").perform();
 
 
 // browser quit
 driver.quit();

} 
}

 

Selenium Tutorial on this website:

https://www.testingdocs.com/selenium-webdriver-tutorial/

More information on Selenium, visit official website:

https://www.selenium.dev/

Related Posts

Selenium /

Add Microsoft Webdriver on Windows OS

Selenium /

Getting Started with Selenium Webdriver

Selenium /

LambdaTest – Testing Cloud SaaS Platform

Selenium /

Selenium 3.0 and Mozilla GeckoDriver

Selenium /

Run an Example Test on SauceLabs

‹ Run BrowserStack Cloud Test› Sample Selenium Framework with TestNG

Recent Posts

  • Scaler Academy – An Online Learning Platform
  • Difference between PHP and JavaScript?
  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com