2017-05-02 6 views
0

私はセレンを使用したことがありません。私のテストでmvn verifyを実行した後に問題が見つかりました。私はwebdriverでJava Junitを使用しています。私はFirefoxのため、この使用してセレンのIDEを生成し、Java/JUnitの/ webdriverをとしてそれをエクスポートセレンテストでmvnを実行しているときにエラーが発生しました

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; 
    } 
    } 
} 

は、ここに私のテストコードです。 SRC /テスト/ Javaでそれを統合/と私はMVN私の端末で実行し、それがテストをロードし検証して終了したときも、私のpom.xml

にnecesary依存関係を追加すると失敗します。

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 

これは、完全なエラーログ:

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) 

はまた、私はXvfbのでhedlessテストを使用しようとしているが、私も自分のローカルマシンでそれを確認することができませんでしだ。私はUbuntuを使用しています17.10

私はこれのためのステップの実装を見つけることができませんでした。または、テストをジェンキンスパイプライン用のjenkinsfileに統合する場合

答えて

0

エラーを解決するには、Geckoドライバに拡張機能を追加する必要があります。

System.setProperty("webdriver.gecko.driver", "/home/francop/Downloads/geckodriver.exe"); 
    WebDriver driver = new FirefoxDriver(); 
関連する問題