2012-11-23 22 views
5

Điều này khiến tôi phát điên. Tôi đang chạy một khuôn khổ thử nghiệm bằng cách sử dụng dưa chuột-jvm và cố gắng để có được nó để chụp ảnh màn hình. Tôi đã xem ví dụ về java-webbit-websockets-selenium được cung cấp và đã triển khai cùng phương pháp gọi trình quản trị web của tôi bằng mô-đun SharedDriver. Vì lý do nào đó, các phương thức @Trước và @After của tôi không được gọi (tôi đã đặt các câu lệnh in trong đó). Co ai đo co thể che đi bong đen nao đo không?Chú thích không kích hoạt trong SharedDriver với dưa chuột-jvm

SharedDriver:

package com.connectors; 

import cucumber.api.java.After; 
import cucumber.api.java.Before; 
import cucumber.api.Scenario; 
import org.openqa.selenium.Dimension; 
import org.openqa.selenium.OutputType; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebDriverException; 
import org.openqa.selenium.chrome.ChromeDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.openqa.selenium.firefox.FirefoxProfile; 
import org.openqa.selenium.support.events.EventFiringWebDriver; 

import java.util.concurrent.TimeUnit; 


public class SharedDriver extends EventFiringWebDriver { 




    private static final WebDriver REAL_DRIVER = new FirefoxDriver(); 

     private static final Thread CLOSE_THREAD = new Thread() { 
      @Override 
      public void run() { 
       REAL_DRIVER.close(); 
      } 
     }; 

     static { 
      Runtime.getRuntime().addShutdownHook(CLOSE_THREAD); 
     } 

     public SharedDriver() { 
      super(REAL_DRIVER); 
      REAL_DRIVER.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 
      REAL_DRIVER.manage().window().setSize(new Dimension(1200,800)); 
      System.err.println("DRIVER"); 
     } 

     @Override 
     public void close() { 
      if(Thread.currentThread() != CLOSE_THREAD) { 
       throw new UnsupportedOperationException("You shouldn't close this WebDriver. It's shared and will close when the JVM exits."); 
      } 
      super.close(); 
     } 

     @Before() 
     public void deleteAllCookies() { 
      manage().deleteAllCookies(); 
      System.err.println("BEFORE"); 
     } 

     @After 
     public void embedScreenshot(Scenario scenario) { 
      System.err.println("AFTER"); 
      try { 
       byte[] screenshot = getScreenshotAs(OutputType.BYTES); 
       scenario.embed(screenshot, "image/png"); 
      } catch (WebDriverException somePlatformsDontSupportScreenshots) { 
       System.err.println(somePlatformsDontSupportScreenshots.getMessage()); 
      } 
     } 


    } 

Bước file:

package com.tests; 

import com.connectors.BrowserDriverHelper; 
import com.connectors.SharedDriver; 
import com.connectors.FunctionLibrary; 

import cucumber.api.Scenario; 
import cucumber.api.java.After; 
import cucumber.api.java.Before; 
import cucumber.api.java.en.And; 
import cucumber.api.java.en.Given; 
import cucumber.api.java.en.Then; 
import cucumber.api.java.en.When; 
import cucumber.runtime.PendingException; 
import org.openqa.selenium.*; 


import java.io.File; 
import java.util.List; 
import java.util.concurrent.TimeUnit; 
import static org.junit.Assert.*; 
import org.openqa.selenium.OutputType; 
import org.openqa.selenium.support.events.EventFiringWebDriver; 

/** 
* Created with IntelliJ IDEA. 
* User: stuartalexander 
* Date: 23/11/12 
* Time: 15:18 
* To change this template use File | Settings | File Templates. 
*/ 
public class addComponentsST { 
    String reportName; 
    String baseUrl = BrowserDriverHelper.getBaseUrl(); 
    private final WebDriver driver; 

    public addComponentsST(SharedDriver driver){ 
     this.driver = driver; 
     driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS); 
    } 

    @Given("^I have navigated to the \"([^\"]*)\" of a \"([^\"]*)\"$") 
    public void I_have_navigated_to_the_of_a(String arg1, String arg2) throws Throwable { 
     // Express the Regexp above with the code you wish you had 
     assertEquals(1,2); 
     throw new PendingException(); 
    } 

CukeRunner:

package com.tests; 

import org.junit.runner.RunWith; 

import cucumber.api.junit.Cucumber; 

@RunWith(Cucumber.class) 
@Cucumber.Options(tags = {"@wip"}, format = { "pretty","html:target/cucumber","json:c:/program files (x86)/jenkins/jobs/cucumber tests/workspace/target/cucumber.json" }, features = "src/resources/com/features") 
public class RunCukesIT { 
} 

Trả lời

5

Đặt SharedDriver trong gói giống như RunCukesIT, ví dụ: com.tests.

Khi sử dụng JUnit runner, keo trở thành gói thử nghiệm đơn vị (ở đây com.tests), và đây là nơi dưa chuột-jvm sẽ “quét” các lớp cho chú thích.

+1

Cảm ơn bạn rất nhiều! Tôi đã bashing đầu của tôi chống lại vấn đề này cho các lứa tuổi :) – theawesome

+0

Tôi đã không may, đủ để có con số này ra một cách khó khăn và vấp ngã trên câu trả lời của bạn sau này. 1 Mặc dù. – Corey

+0

Xin chào các bạn. Hãy để tôi hỏi một câu hỏi liên quan đến điều này. Tôi cần làm gì để khởi tạo trình quản trị web nếu tôi có nhiều tệp bước và đối tượng nhiều trang cho mỗi trang trên trang web. Ngay bây giờ, mọi lớp đối tượng trang mở rộng lớp BasePage.class chứa tất cả sự khởi tạo cho khung công tác. Nhưng tôi đang bối rối trong trường hợp của trình điều khiển được chia sẻ như thế nào tôi có thể xử lý nó! Cảm ơn bạn! – brobee

Các vấn đề liên quan