Maximize browser window

0 votes

Some websites implemented responsive design. So, the website looks differently on smaller screens.
Therefore it’s important to maximize the browser window before the test starts.

@Test
public void maximizeFirefox() {
  // Start browser
  System.setProperty("webdriver.gecko.driver", FileUtil.findFileOnPath("mac/geckodriver"));
  final FirefoxDriver driver = new FirefoxDriver();

  // Maximize browser
  driver.manage().window().maximize();

  // Open website
  driver.get("http://www.selenium-in-action.io");
}

There are several bug reports noticing that this feature doesn’t work when using ChromeDriver.
Luckily the is a workaround, we can start Chrome in kiosk mode (full screen without toolbars).

@Test
public void startChromeFullscreen() {
  // Start browser with specific options
  final ChromeOptions options = new ChromeOptions();
  options.addArguments("start-fullscreen");
  System.setProperty("webdriver.chrome.driver", FileUtil.findFileOnPath("mac/chromedriver"));
  final ChromeDriver driver = new ChromeDriver(options);

  // Open website 
  driver.get("http://www.selenium-in-action.io");
}

Kiosk mode

@Test
public void startChromeKioskMode() {
  // Start browser with specific options  
  final ChromeOptions options = new ChromeOptions();
  options.addArguments("--kiosk");
  System.setProperty("webdriver.chrome.driver", FileUtil.findFileOnPath("mac/chromedriver"));
  final ChromeDriver driver = new ChromeDriver(options);

  // Open website 
  driver.get("http://www.selenium-in-action.io");
}
Please follow and like us:
Follow by Email
Facebook
Google+
http://www.seleniuminaction.com/maximize-browser-window/
Twitter
LinkedIn

Locators

0 votes

Locators are the way to tell Selenium WebDriver with which web element we like to do something (It can be literally anything, like: `clicking`, `typing`, `selecting`, `verifying`, and so on).

Selenium WebDriver provides different ways of locating those web elements; we call this the locating strategy. In Selenium WebDriver we can locate web elements by CSS, XPath, Name, Id, and even Link text. We have to define the locators our self, so we have full control over it.

The CSS locating strategy is recommended for three reasons:

  1. It’s faster;
  2. It’s more readable;
  3. It’s more used.

It depends on the browser, but in Internet Explorer the XPath locators are 2 (up to 3) times slower than CSS locators. XPath is implemented differently amongst browsers. CSS locators require very low maintenance, because the syntax is readable and understandable. Beside of that, CSS locators are more used in projects, for example by designers or jQuery experts (which is a frequently used JavaScript library).

It becomes unnecessary hard to interact with elements on the page if there are no unique identifiers. So, try to convince the developers to add some handy identifiers.

General advice might be to use the locator strategies in the following order: id > name > CSS > XPath > angular. Only use XPath if we need to walk up the DOM.

Please follow and like us:
Follow by Email
Facebook
Google+
http://www.seleniuminaction.com/locators/
Twitter
LinkedIn

Implement Maintainable Test Scripts by Applying Design Patterns

0 votes

My article on Software Developer’s Journal is republished.

Link to article: https://sdjournal.org/implement-maintainable-test-scripts-applying-design-patterns/

This might be a good first step in the learning journey of becoming a skilled test automation craftsman.

Please let me know if you have any comments.

Please follow and like us:
Follow by Email
Facebook
Google+
http://www.seleniuminaction.com/implement-maintainable-test-scripts-by-applying-design-patterns/
Twitter
LinkedIn

Loop through WebElements using Java 8

0 votes

It’s quite common to have a list of WebElements where we want to iterate over. We can use the Java 8 Stream API feature to easily iterate over collections.


final List<String> productNames = driver
.findElements(By.cssSelector("ul.product_list a.product-name")).stream()
.map(WebElement::getText).collect(Collectors.toList());

Please follow and like us:
Follow by Email
Facebook
Google+
http://www.seleniuminaction.com/loop-through-webelements-using-java-8/
Twitter
LinkedIn