0

I'm new using Selenium and I find a problem after running mvn verify with my test included in my code. I'm using Java Junit with webdriver.

Here is my test code:

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class SeleniumTest {
  private WebDriver driver;
  private String baseUrl;
  private boolean acceptNextAlert = true;
  private StringBuffer verificationErrors = new StringBuffer();

  public static void main(String[] args) {

      System.setProperty("webdriver.gecko.driver", "/home/francop/Downloads/geckodriver");
      WebDriver driver = new FirefoxDriver();

      driver.get("http://localhost:8448/login");

      driver.quit();
  }

  @Before
  public void setUp() throws Exception {
      System.setProperty("webdriver.gecko.driver", "/home/francop/Downloads/geckodriver");
    driver = new FirefoxDriver();
    baseUrl = "http://localhost:8448/login";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  }

  @Test
  public void testSelenium() throws Exception {
    driver.get(baseUrl);
    driver.findElement(By.name("username")).clear();
    driver.findElement(By.name("username")).sendKeys("dbaranowski");
    driver.findElement(By.name("password")).clear();
    driver.findElement(By.name("password")).sendKeys("dbaranowski");
    driver.findElement(By.cssSelector("input[type=\"submit\"]")).click();
    driver.findElement(By.id("searchBtn")).click();
    driver.findElement(By.id("icon")).click();
    driver.findElement(By.id("filter-button")).click();
    driver.findElement(By.id("clear-button")).click();
    driver.findElement(By.id("filter-button")).click();
    driver.findElement(By.id("clear-button")).click();
    driver.findElement(By.id("input")).click();
    driver.findElement(By.xpath("//div[@id='contentWrapper']/div/paper-listbox/paper-item")).click();
    driver.findElement(By.id("filter-button")).click();
    driver.findElement(By.id("scrim")).click();
    driver.findElement(By.xpath("(//input[@value='MORON                         '])[4]")).click();
    driver.findElement(By.cssSelector("#infoBtn > #icon")).click();
    driver.findElement(By.xpath("//paper-dialog[@id='affectedClientsDetail']/div[5]/paper-button[3]")).click();
    driver.findElement(By.xpath("(//input[@value='MORON                         '])[16]")).click();
    driver.findElement(By.cssSelector("#infoBtn > #icon")).click();
    driver.findElement(By.id("insertClientBtn")).click();
    driver.findElement(By.xpath("//vaadin-grid[@id='grid']/div/div[3]")).click();
    driver.findElement(By.xpath("(//input[@value='MORON                         '])[13]")).click();
    driver.findElement(By.cssSelector("#infoBtn > #icon")).click();
    driver.findElement(By.xpath("//vaadin-grid[@id='grid']/div/div[3]")).click();
    driver.findElement(By.xpath("(//input[@value='MORON                         '])[16]")).click();
    driver.findElement(By.cssSelector("#infoBtn > #icon")).click();
    driver.findElement(By.id("insertClientBtn")).click();
    driver.findElement(By.xpath("//vaadin-grid[@id='grid']/div/div[3]")).click();
    driver.findElement(By.xpath("(//input[@value='MORON                         '])[13]")).click();
    driver.findElement(By.cssSelector("#infoBtn > #icon")).click();
    driver.findElement(By.id("infoBtn")).click();
    driver.findElement(By.id("insertClientBtn")).click();
    driver.findElement(By.xpath("(//input[@id='input'])[13]")).clear();
    driver.findElement(By.xpath("(//input[@id='input'])[13]")).sendKeys("0387722559");
    driver.findElement(By.xpath("(//iron-icon[@id='icon'])[32]")).click();
    driver.findElement(By.xpath("//iron-collapse[@id='collapse1']/div[2]/paper-button")).click();
    driver.findElement(By.id("modifyInt")).click();
    driver.findElement(By.xpath("//paper-dialog[@id='affectedClientsDetail']/div[3]/paper-button")).click();
    driver.findElement(By.cssSelector("#exportBtn > #icon")).click();
    driver.findElement(By.cssSelector("body.layout.vertical > #exportDialog > div.buttons > paper-button.x-scope.paper-button-0")).click();
    driver.findElement(By.cssSelector("#selection-button > #icon")).click();
    driver.findElement(By.xpath("//button[@type='button']")).click();
    driver.findElement(By.id("gwt-uid-3")).click();
    driver.findElement(By.id("gwt-uid-4")).click();
    driver.findElement(By.id("gwt-uid-5")).click();
    driver.findElement(By.id("gwt-uid-6")).click();
    driver.findElement(By.id("gwt-uid-7")).click();
    driver.findElement(By.id("gwt-uid-8")).click();
    driver.findElement(By.id("gwt-uid-9")).click();
    driver.findElement(By.cssSelector("#gwt-uid-10 > span.v-on > div")).click();
    driver.findElement(By.id("gwt-uid-11")).click();
    driver.findElement(By.id("gwt-uid-12")).click();
    driver.findElement(By.id("gwt-uid-13")).click();
    driver.findElement(By.cssSelector("#gwt-uid-14 > span.v-on > div")).click();
    driver.findElement(By.cssSelector("#gwt-uid-15 > span.v-on > div")).click();
    driver.findElement(By.cssSelector("#gwt-uid-16 > span.v-on > div")).click();
    driver.findElement(By.id("gwt-uid-16")).click();
    driver.findElement(By.id("gwt-uid-15")).click();
    driver.findElement(By.id("gwt-uid-14")).click();
    driver.findElement(By.id("gwt-uid-13")).click();
    driver.findElement(By.id("gwt-uid-12")).click();
    driver.findElement(By.xpath("//button[@type='button']")).click();
    driver.findElement(By.cssSelector("#copy-button > #icon")).click();
    driver.findElement(By.id("gwt-uid-47")).click();
    driver.findElement(By.cssSelector("label.vaadin-grid.style-scope")).click();
    driver.findElement(By.cssSelector("#selection-button > #icon")).click();
    driver.findElement(By.id("icon")).click();
    driver.findElement(By.xpath("//div[@id='tabsContent']/paper-tab[2]/div")).click();
    driver.findElement(By.id("icon")).click();
    driver.findElement(By.id("paperToggle")).click();
    driver.findElement(By.xpath("//div[@id='tabsContent']/paper-tab[2]/div")).click();
    driver.findElement(By.id("paperToggle")).click();
    driver.findElement(By.xpath("(//div[@id='checkboxContainer'])[23]")).click();
    driver.findElement(By.xpath("(//iron-icon[@id='icon'])[10]")).click();
    driver.findElement(By.xpath("(//div[@id='buttons']/paper-checkbox)[3]")).click();
    driver.findElement(By.xpath("(//div[@id='buttons']/paper-checkbox)[2]")).click();
    driver.findElement(By.xpath("(//div[@id='checkboxContainer'])[20]")).click();
    driver.findElement(By.xpath("(//iron-icon[@id='icon'])[9]")).click();
    driver.findElement(By.xpath("//div[@id='tabsContent']/paper-tab/div")).click();
    driver.findElement(By.id("filter-button")).click();
    driver.findElement(By.id("scrim")).click();
    driver.findElement(By.id("searchBtn")).click();
    driver.findElement(By.cssSelector("#logoutBtn > #icon")).click();
    driver.findElement(By.cssSelector("#logoutDialog > div.buttons > paper-button.x-scope.paper-button-0")).click();
    driver.findElement(By.name("username")).clear();
    driver.findElement(By.name("username")).sendKeys("");
    driver.findElement(By.name("password")).clear();
    driver.findElement(By.name("password")).sendKeys("");
  }

  @After
  public void tearDown() throws Exception {
    driver.quit();
    String verificationErrorString = verificationErrors.toString();
    if (!"".equals(verificationErrorString)) {
      fail(verificationErrorString);
    }
  }

  private boolean isElementPresent(By by) {
    try {
      driver.findElement(by);
      return true;
    } catch (NoSuchElementException e) {
      return false;
    }
  }

  private boolean isAlertPresent() {
    try {
      driver.switchTo().alert();
      return true;
    } catch (NoAlertPresentException e) {
      return false;
    }
  }

  private String closeAlertAndGetItsText() {
    try {
      Alert alert = driver.switchTo().alert();
      String alertText = alert.getText();
      if (acceptNextAlert) {
        alert.accept();
      } else {
        alert.dismiss();
      }
      return alertText;
    } finally {
      acceptNextAlert = true;
    }
  }
}

I generate this using selenium IDE for firefox and exported it as Java / Junit / Webdriver. Integrating it in src/test/java/ and also adding the necesary dependencies to my pom.xml

When I run in my terminal mvn verify it loads the test and finish with fail:

Failed tests: 
SeleniumTest.testSelenium on testSelenium(SeleniumTest)(SeleniumTest)
  Run 1: SeleniumTest.setUp:29 ยป IllegalAccess tried to access class org.openqa.seleniu...
  Run 2: SeleniumTest.tearDown:130 NullPointer

This is the full error log:

java.lang.IllegalAccessError: tried to access class org.openqa.selenium.os.ExecutableFinder from class org.openqa.selenium.firefox.FirefoxBinary
    at org.openqa.selenium.firefox.FirefoxBinary.locateFirefoxBinariesFromPlatform(FirefoxBinary.java:412)
    at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:108)
    at java.util.Optional.orElseGet(Optional.java:267)
    at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:204)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:108)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:104)
    at SeleniumTest.setUp(SeleniumTest.java:29)

testSelenium on testSelenium(SeleniumTest)(SeleniumTest)  Time elapsed: 0.184 sec  <<< FAILURE!
java.lang.NullPointerException: null
    at SeleniumTest.tearDown(SeleniumTest.java:130)

Also I'm trying to use hedless test with Xvfb but I'm unable to even verify it in my local machine. I'm using Ubuntu 17.10

I wasn't able to find any step by step implementation for this. Or for integrate the test into jenkinsfile for a jenkins pipeline

Franco Papalardo
  • 371
  • 1
  • 2
  • 18

1 Answers1

0

You should add extension to the Gecko Driver to resolve one of the error.

  System.setProperty("webdriver.gecko.driver", "/home/francop/Downloads/geckodriver.exe");
  WebDriver driver = new FirefoxDriver();
Chandra Shekhar
  • 664
  • 2
  • 9
  • 24