Selenium

Behat Mink: 000 - Blocking Issues in Mink for Drupal

  • Mink is probably a great tool for basic websites that don't implement a heavy back-end system.
  • Mink COULD be a winner IF
    • migrates to selenium3 webdriver
    • exposes the entire selenium3 api
    • provides a means to send XPATH directly to selenium api
      • currently catches, parses, translates, THEN sends to api
    • provides a means to send CSS directly to selenium api
      • currently catches, parses, translates, THEN sends to api

Behat front end is a solid Cucumber BDD Engine

  • Still requires a sensible & well-designed test framework to hook into
  • Design the framework around PHPUnit
  • Use Behat to provide BDD translation for feature files
  • BDD isn't test...

Behat Mink: 00 - Selenium

Selenium

Download the latest version of Selenium Server It’s under the heading Selenium Server (formerly the Selenium RC Server). This is a single file which can be placed any where you like on your system and run with the following command:

java -jar selenium-server-standalone-2.44.0.jar &
// replace with the name of the version you downloaded

 

Java: Retrieving OS & Browser Versions with Selenium WebDriver

GetEnvInfo Class

  • Uses WebDriver to get the Browser type/version
  • Uses SystemProperty to get OS Type
package com.cs.cmsauto.utilities;

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.RemoteWebDriver;

public class GetEnvInfo {
    private static WebDriver browserDriver;

    public static String getBrowserAndVersion() {
        String browser_version = null;
        Capabilities cap = ((RemoteWebDriver) browserDriver).getCapabilities();
        String browsername = cap.getBrowserName();
        // This block to find out IE Version number
        if ("internet explorer".equalsIgnoreCase(browsername)) {
            String uAgent = (String) ((JavascriptExecutor) browserDriver).executeScript("return navigator.userAgent;");
            System.out.println(uAgent);
            // uAgent return as "MSIE 8.0 Windows" for IE8
            if (u
Tags

C#: Selenium Selectors

Drupal8 Logout Link at footer ( XPath vs LinkText )

  • Had MUCH difficulty hooking into the logout link using XPATH for
  • JS window.scrollTo
  • By.LinkText(“Log out”) seems to be more accessible
  • using By.LinkText allowed Selenium to natively 'scroll to' on the 'Click()' method

Selenium basic selectors

XPath

el = driver.FindElement(By.XPath("//a[@href='/uc/user/logout']"));

Id

el = driver.FindElement(By.Id("username"));

LinkText

el = driver.FindElement(By.LinkText("Log out"));

JS scrollIntoView

  • when element found by XPath(//a), this didn't work
el = driver.FindElement(By.LinkText("Log out"));
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].scrollIntoView(true);", el);

ILoc

Tags

SpecFlow: 03 - Selenium POM PageObjects & PageActions

Test Definitions For Selenium POM

  • While Selenium3 has done away with the attribute-driven PageFactory, the PageObject Model is still applicable

POM - Page Objects

PageBaseClass

  • Create a BaseClass that will be used for the PageObject classes & their static methods
  • Settings that will be common to all page objects can also reside here, though this base class can simply consume & return the 'driver'
  • The PageObject clases will extend the BaseClass & provide static methods to be called from the PageActions classes

Home_Page

IWebElement = el;

public static void Login_Link(){

el = findElement(By.XPath("//a[@href='/login/']");

}

Login_Link()

Logout_Link()

Login_Page

TxtBox_Username()

TxtBox_Password()

Btn_LoginButton()

Java POM: 09-Selenium Tricks

Common Selector Strategies

Page Title

return driver.getTitle();

 

findElement(By.id

element = driver.findElement(By.id("edit-field-tags-target-id"));
return element;

 

findElement(By.xpath

element = driver.findElement(By.xpath("//iframe[@title='Rich Text Editor, Body field']"));

 

Explicit Waits

int timeoutSec = 15;
WebDriverWait wait = new WebDriverWait(driver, timeoutSec);
wait.until((driver) -> driver.findElements(By.xpath("//a[@href='/uc/user/login']")).size()>0);
wait.until((driver) -> driver.findElement(By.xpath("//a[@href='/uc/user/login']")).isDisplayed());

 

Tags
Subscribe to Selenium