2016-12-30 116 views
1

我使用webdriver的硒3.0和硒的Javajava.lang.IllegalStateException:眼睛無法打開

<dependency> 
      <groupId>com.applitools</groupId> 
      <artifactId>eyes-selenium-java</artifactId> 
      <version>2.54</version> 
</dependency> 

對於視覺測試AppliToolsEyes 2.54寫下下面的代碼 -

private WebDriver driver; 
private Eyes eyes; 
private static final String url = "http://www.google.com"; 

@BeforeClass 
public void setUp(){ 
    eyes = new Eyes(); 
    System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir") + "//src//test//resources//geckodriver.exe"); 
    driver = new FirefoxDriver(); 
    driver.manage().window().maximize(); 
} 

@AfterClass 
public void tearDown(){ 
    eyes.abortIfNotClosed(); 
    driver.quit(); 
} 

@Test 
public void visualTest(){ 
    eyes.checkWindow(); 
    driver.get(url); 
    eyes.checkWindow(); 
    eyes.close(); 
} 

,但得到以下錯誤時運行的代碼eyes.checkWindow()

java.lang.IllegalStateException: Eyes not open at com.applitools.utils.ArgumentGuard.isValidState(ArgumentGuard.java:117) at com.applitools.eyes.EyesBase.checkWindowBase(EyesBase.java:977) at com.applitools.eyes.Eyes.checkWindow(Eyes.java:359) at com.applitools.eyes.Eyes.checkWindow(Eyes.java:335) at com.applitools.eyes.Eyes.checkWindow(Eyes.java:325)

回答

0

爲了解決這個問題,你需要檢查窗口之前睜眼。

這樣做的一種方式是在測試的開頭添加以下行,如下所示:

@Test 
public void visualTest(){ 
    driver = eyes.open(driver, appName, testName, new RectangleSize(width, height)); 
    eyes.checkWindow(); 
    driver.get(url); 
    eyes.checkWindow(); 
    eyes.close(); 
} 

或者添加JUnit的規則,這將單獨打開的眼睛對每個測試:

@Rule 
    public TestWatcher watcher = new TestWatcher() { 
     protected void starting(Description description) { 
      eyes.open(driver, appName, description.getMethodName(), new RectangleSize(width, height)); 
     } 
    }; 

在另一個問題上,我看到在你的測試中,你正在調用: driver.manage()。window()。maximize(); 這種設置瀏覽器大小的方式可能會導致不穩定的視覺測試 - 您應該在打開眼睛時指定視口大小。

欲瞭解更多信息,請查看this article關於在Applitools測試中設置視口尺寸,或聯繫[email protected]