Selenium Plugin - Macros


# EXECUTE_SELENIUM2 {bundlePath} WITH MAIN CLASS {mainClassName}

What ?

This macro will compile the selenium 2 test suite contained in the specified bundle and execute the specified test suite (main class) from the bundle.

Underlying instructions :

LOAD {bundlePath} AS __temp_{%%rand1}.file
CONVERT __temp_{%%rand1}.file TO script.java(compile) AS __temp_{%%rand2}.compiled
CONVERT __temp_{%%rand2}.compiled TO script.java.selenium2(script) USING $({mainClassName}) AS __temp_{%%rand3}.selenium
EXECUTE execute WITH __temp_{%%rand3}.selenium AS __temp_{%%rand4}.result
ASSERT __temp_{%%rand4}.result IS success

> Input :

  • {bundlePath} : The path to the selenium bundle to execute relative to the resources repository. You have to point to the folder containing the java folder.
  • {mainClassName} : The qualified name of the main class.

Example :

# EXECUTE_SELENIUM2 path/to/selenium2 WITH MAIN CLASS com.example.selenium.TestSuite

Selenium bundle location :

../../_images/execute-selenium2-macro-selenium-bundle-location.png

SKF script :

../../_images/execute-selenium2-macro.png

Main class :

package seleniumExample;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.util.concurrent.TimeUnit;

public class SeleniumExample {

    WebDriver driver;
    WebDriverWait wait;

    @Before
    public void setUp(){
        try{
            driver = new FirefoxDriver();
            driver.get("https://www.bbc.com/news");

        }
        catch(Exception e){
            System.err.println(e.getMessage());
        }
        driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
        wait = new WebDriverWait(driver,30);
    }

    @Test
    public void randomTest() throws InterruptedException {
        driver.findElement(By.xpath("//input[@id='orb-search-q']")).sendKeys("selenium");
                String value = driver.findElement(By.xpath("//button[@id='orb-search-button']")).getText();
        Assert.assertTrue("The search button doesn't exist", value.equals("Search the BBC"));
    }

    @After
    public void tearDown(){
        //driver.quit();
    }
}