title: JavaFX vs Serenity
body: <p>I would like to do a small test using JavaFX and Serenity BDD, unfortunately with failure.</p>
  
  <p>-when my code calls manually from the "TestSer" class it works fine.</p>
  
  <p>-when calls from the GUI unfortunately does not work.</p>
  
  <p>It seems to me that I am making a simple mistake with calling this class but I lack this knowledge
  I present to you my code and please help.</p>
  
  <p>Test class</p>
  
  <pre><code>@RunWith(SerenityRunner.class)
  public class TestSer extends PageObject {
  
      public Logger logger = LoggerFactory.getLogger(this.getClass());
      @Managed
      public WebDriver driver;
      @FindBy(id = "b-7")
      private WebElementFacade inputNumber;
  
      @FindBy(id = "b-8")
      private WebElementFacade buttonCheck;
  
      @FindBy(id = "b-9")
      private WebElementFacade buttonClean;
  
      @FindBy(id = "caption2_b-3")
      private WebElementFacade result;
  
      Page page = new Page();
      String[] arr = {"1230391507", "1230943800","1230705176", "1230943800", "1231069185", "1230500907", "1231079746"};
  
      @Test
      public  void  dodo() throws Exception {
          page.open();
          for (int i = 0; i &lt; arr.length; i++) {
              page.check( arr[i] );
              System.out.println( arr[i] );
          }
      }
  
      public void check(String numer)  throws Exception {
          String teraz = Teraz();
  
          waitFor( inputNumber ).waitUntilEnabled();
          inputNumber.type( numer );
          waitFor( buttonCheck ).isClickable();
          buttonCheck.click();
          this.takeSnapShot(getDriver(), "C:\\Users\\smyha\\OneDrive\\Pulpit\\z\\"+numer+ teraz+  ".png") ;
          waitFor( buttonClean ).isClickable();
          buttonClean.click();
          pause( 2000 );
  
  
  
  
      }
  
      public static void takeSnapShot(WebDriver webdriver, String fileWithPath) throws Exception{
          TakesScreenshot scrShot =((TakesScreenshot)webdriver);
          File SrcFile=scrShot.getScreenshotAs( OutputType.FILE);
          File DestFile=new File(fileWithPath);
          FileUtils.copyFile(SrcFile, DestFile);
      }
  
      public void pause(Integer milliseconds){
          try {
              TimeUnit.MILLISECONDS.sleep(milliseconds);
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
      }
  
      public String Teraz (){
          Date date = new Date(); //
          SimpleDateFormat hh = new SimpleDateFormat("HH");
          SimpleDateFormat mm = new SimpleDateFormat("mm");
          SimpleDateFormat ss = new SimpleDateFormat("ss");
          String h = hh.format(date);
          String m = mm.format(date);
          String s = ss.format(date);
          String teraz = "_"+h+"_"+m+"_"+s;
  
          return teraz;
      }
  </code></pre>
  
  <p>Controller class</p>
  
  <pre><code>@RunWith(SerenityRunner.class)
  public class Controller implements Initializable {
      public static final String dane = "1230391507\n" +
              "1230500907\n" +
              "1230705176\n" +
              "1230943800\n" +
              "1231069185\n" +
              "1231079746\n";
      public String [] arr ;
      public String outDir;
  
      private Window stage;
      public  String dirdir;
      public String[] getArr() {
          return arr;
      }
  
      public void setArr(String[] arr) {
          this.arr = arr;
      }
  
      @FXML
      private JFXTextArea  txtFiield;
      @FXML
      private  JFXTextField txtWhere;
  
      @FXML
      private JFXButton btnWhere, btnRun;
  
      @Override
      public void initialize(URL location, ResourceBundle resources) {
          txtFiield.setText( dane );
      }
  
  
      public void doWhere(ActionEvent actionEvent) {
          DirectoryChooser directoryChooser = new DirectoryChooser();
          File selectedDirectory = directoryChooser.showDialog(stage);
  
          if(selectedDirectory == null){
          }else{
              txtWhere.setText( selectedDirectory.getAbsolutePath() +  "\\");
              dirdir =  selectedDirectory.getAbsolutePath() + "\\";
          }
          if (txtFiield.getLength() &gt;0 &amp;&amp; txtWhere.getLength() &gt;0){
             // btnWhere.setDisable( false );
              btnRun.setDisable( false );
          }
      }
  
      @Test
      public void doRun(ActionEvent actionEvent) throws Exception {
          TestSer t = new TestSer();
          t.dodo();
      }
      public void parseField(String wejsciowe){
          setArr( null );
          setArr( wejsciowe.split( "\n" ));
          System.out.println(arr.length);
  
          String[] a = getArr();
          for(int i = 0; i &lt; a.length; i++){
  
              if(a[i].length() != 10){
                  infoBox( "nieprawidłowa długość NIPu w lini : ", "Niepoprawne dane", "Błąd", i+1 );
              }
          }
      }
  public static void infoBox(String infoMessage, String headerText, String title, int line){
      Alert alert = new Alert( Alert.AlertType.CONFIRMATION);
      alert.setContentText(infoMessage + line);
      alert.setTitle(title);
      alert.setHeaderText(headerText);
      alert.showAndWait();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Errors:</p>
  
  <pre><code>log4j:WARN No appenders could be found for logger (net.thucydides.core.util.PropertiesFileLocalPreferences).
  log4j:WARN Please initialize the log4j system properly.
  log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
  Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
      at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774)
      at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
      at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
      at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
      at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
      at javafx.event.Event.fireEvent(Event.java:198)
      at javafx.scene.Node.fireEvent(Node.java:8411)
      at javafx.scene.control.Button.fire(Button.java:185)
      at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
      at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
      at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
      at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
      at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
      at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
      at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
      at javafx.event.Event.fireEvent(Event.java:198)
      at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
      at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
      at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
      at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:394)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
      at java.security.AccessController.doPrivileged(Native Method)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$353(GlassViewEventHandler.java:432)
      at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
      at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
      at com.sun.glass.ui.View.notifyMouse(View.java:937)
      at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
      at java.lang.Thread.run(Thread.java:748)
  Caused by: java.lang.reflect.InvocationTargetException
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
      at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
      at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
      ... 52 more
  Caused by: java.lang.NullPointerException
      at net.serenitybdd.core.pages.PageObject.openPageAtUrl(PageObject.java:902)
      at net.serenitybdd.core.pages.PageObject.open(PageObject.java:803)
      at net.serenitybdd.core.pages.PageObject.open(PageObject.java:791)
      at com.sub.serenity.TestSer.dodo(TestSer.java:48)
      at com.sub.Controller.doRun(Controller.java:81)
      ... 62 more
  </code></pre>