@Test
  public void oneToOneRelationBetweenBrowserAndUI() throws MalformedURLException {

    openWindow(INSTRUMENTED_UI_URI);

    firstWindow.click(BUTTON);
    waitModel.waitForChange(retrieveText.locator(LABEL));
    int clickCount = number(firstWindow.getText(LABEL));
    assertThat(clickCount, is(1));
    assertThat(InstrumentedUI.getNumberOfInstances(), is(1));

    firstWindow.click(BUTTON);
    waitModel.waitForChange(retrieveText.locator(LABEL));
    clickCount = number(firstWindow.getText(LABEL));
    assertThat(clickCount, is(2));
    assertThat(InstrumentedUI.getNumberOfInstances(), is(1));

    firstWindow.restartBrowser();
    openWindow(INSTRUMENTED_UI_URI);

    firstWindow.click(BUTTON);
    waitModel.waitForChange(retrieveText.locator(LABEL));
    clickCount = number(firstWindow.getText(LABEL));
    assertThat(clickCount, is(1));
    assertThat(InstrumentedUI.getNumberOfInstances(), is(2));

    firstWindow.click(BUTTON);
    waitModel.waitForChange(retrieveText.locator(LABEL));
    clickCount = number(firstWindow.getText(LABEL));
    assertThat(clickCount, is(2));
    assertThat(InstrumentedUI.getNumberOfInstances(), is(2));
    assertDefaultRootNotInstantiated();
  }
 @Test
 public void browserRestartCreatesNewInstance() throws MalformedURLException {
   String uri = deriveMappingForUI(PlainUI.class);
   openWindow(uri);
   assertTrue("PlainUI should contain a label", firstWindow.isElementPresent(LABEL));
   assertThat(PlainUI.getNumberOfInstances(), is(1));
   // reset session
   firstWindow.restartBrowser();
   openWindow(uri);
   assertTrue("PlainUI should contain a label", firstWindow.isElementPresent(LABEL));
   assertThat(PlainUI.getNumberOfInstances(), is(2));
   assertDefaultRootNotInstantiated();
 }
 @Test
 public void interceptedScopedEventListener() throws MalformedURLException {
   assertThat(InterceptedUI.getNumberOfInstances(), is(0));
   assertThat(InstrumentedInterceptor.getCounter(), is(0));
   String uri = deriveMappingForUI(InterceptedUI.class);
   openWindow(uri);
   waitModel.until(elementPresent.locator(LABEL));
   firstWindow.click(BUTTON);
   waitModel.waitForChange(retrieveText.locator(LABEL));
   assertThat(InstrumentedInterceptor.getCounter(), is(1));
   firstWindow.click(BUTTON);
   waitModel.waitForChange(retrieveText.locator(LABEL));
   assertThat(InstrumentedInterceptor.getCounter(), is(2));
 }
示例#4
0
  public void takeScreenshot(String command) {
    BrowserType browser = configuration.getBrowser().getType();
    BufferedImage screenshot = null;
    File imageOutputFile =
        new File(
            screenshotsOutputDir,
            MetamerTestInfo.getAssociatedFilename(method) + "/" + getFileName(command));

    if (browser == BrowserType.FIREFOX) {
      screenshot = selenium.captureEntirePageScreenshot();
      File directory = imageOutputFile.getParentFile();

      String newHash = calculateHash(screenshot);
      if (lastImageHash == null || !lastImageHash.equals(newHash)) {

        try {
          FileUtils.forceMkdir(directory);
          calculateHash(screenshot);
          ImageIO.write(screenshot, "PNG", imageOutputFile);
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
        lastImageHash = newHash;
      }
    }
  }
 @Test
 public void cdiEventsArrivesInTheSameUIScopedInstance() throws MalformedURLException {
   assertThat(UIWithCDISelfListener.getNumberOfInstances(), is(0));
   assertThat(UIWithCDISelfListener.getNumberOfDeliveredEvents(), is(0));
   String uri = deriveMappingForUI(UIWithCDISelfListener.class);
   openWindow(uri);
   waitModel.until(elementPresent.locator(LABEL));
   firstWindow.click(BUTTON);
   waitModel.waitForChange(retrieveText.locator(LABEL));
   assertThat(UIWithCDISelfListener.getNumberOfInstances(), is(1));
   assertThat(UIWithCDISelfListener.getNumberOfDeliveredEvents(), is(1));
   firstWindow.click(BUTTON);
   waitModel.waitForChange(retrieveText.locator(LABEL));
   assertThat(UIWithCDISelfListener.getNumberOfInstances(), is(1));
   assertThat(UIWithCDISelfListener.getNumberOfDeliveredEvents(), is(2));
 }
  @Test
  public void dependentScopedViewIsInstantiatedOnce() throws MalformedURLException {
    String uri = deriveMappingForUI(NoViewProviderNavigationUI.class);
    openWindow(uri);
    assertThat(InstrumentedView.getNumberOfInstances(), is(1));
    firstWindow.click(NAVIGATE_BUTTON);
    waitModel.waitForChange(retrieveText.locator(LABEL));
    assertThat(InstrumentedView.getNumberOfInstances(), is(1));
    assertThat(NoViewProviderNavigationUI.getNumberOfInstances(), is(1));
    assertThat(NoViewProviderNavigationUI.getNumberOfNavigations(), is(1));

    firstWindow.click(NAVIGATE_BUTTON);
    waitModel.waitForChange(retrieveText.locator(LABEL));
    assertThat(InstrumentedView.getNumberOfInstances(), is(1));
    assertThat(NoViewProviderNavigationUI.getNumberOfInstances(), is(1));
    assertThat(NoViewProviderNavigationUI.getNumberOfNavigations(), is(2));
  }
 @Test
 public void dependentScopedViewIsInstantiatedTwiceWithViewProvider()
     throws MalformedURLException {
   openWindow(firstWindow, INSTRUMENTED_VIEW_URI);
   firstWindow.click(NAVIGATE_BUTTON);
   waitModel.waitForChange(retrieveText.locator(LABEL));
   assertThat(InstrumentedView.getNumberOfInstances(), is(2));
 }
 @Test
 public void danglingViewCauses404() throws MalformedURLException {
   openWindow(DANGLING_VIEW_URI);
   waitModel.until(elementPresent.locator(LABEL));
   firstWindow.click(NAVIGATE_BUTTON);
   waitModel.waitForChange(retrieveText.locator(LABEL));
   assertThat(SecondUI.getNumberOfInstances(), is(1));
   assertThat(DanglingView.getNumberOfInstances(), is(0));
 }
 @Test
 public void refreshButtonCreatesNewUIInstance() throws MalformedURLException {
   openWindow(INSTRUMENTED_UI_URI);
   assertThat(InstrumentedUI.getNumberOfInstances(), is(1));
   firstWindow.refresh();
   waitModel.until(elementPresent.locator(LABEL));
   assertThat(InstrumentedUI.getNumberOfInstances(), is(2));
   assertDefaultRootNotInstantiated();
 }
 @Test
 public void recognitionOfViewWithoutAnnotation() throws MalformedURLException {
   ParameterizedNavigationUI.NAVIGATE_TO = "viewWithoutAnnotation";
   openWindow(deriveMappingForUI(ParameterizedNavigationUI.class));
   firstWindow.click(NAVIGATE_BUTTON);
   waitModel.waitForChange(retrieveText.locator(LABEL));
   assertThat(ViewWithoutAnnotation.getNumberOfInstances(), is(1));
   assertDefaultRootNotInstantiated();
 }
 @Test
 public void ejbInvocation() throws MalformedURLException {
   openWindow(deriveMappingForUI(EnterpriseUI.class));
   waitModel.waitForChange(retrieveText.locator(LABEL));
   assertThat(EnterpriseUI.getNumberOfInstances(), is(1));
   firstWindow.click(BUTTON);
   waitModel.waitForChange(retrieveText.locator(LABEL));
   final String labelText = retrieveText.locator(LABEL).retrieve();
   assertThat(labelText, startsWith("Echo:"));
   assertThat(EnterpriseUI.getNumberOfInstances(), is(1));
   assertDefaultRootNotInstantiated();
 }
 @Test
 public void navigationToRestrictedViewFails() throws MalformedURLException {
   assertThat(ParameterizedNavigationUI.getNumberOfInstances(), is(0));
   assertThat(RestrictedView.getNumberOfInstances(), is(0));
   ParameterizedNavigationUI.NAVIGATE_TO = deriveMappingForView(RestrictedView.class);
   openWindow(deriveMappingForUI(ParameterizedNavigationUI.class));
   firstWindow.click(NAVIGATE_BUTTON);
   waitModel.waitForChange(retrieveText.locator(LABEL));
   assertThat(ParameterizedNavigationUI.getNumberOfInstances(), is(1));
   assertThat(RestrictedView.getNumberOfInstances(), is(0));
   assertDefaultRootNotInstantiated();
 }
 @Before
 public void resetCounter() {
   PlainUI.resetCounter();
   PlainAlternativeUI.resetCounter();
   PlainColidingAlternativeUI.resetCounter();
   InstrumentedUI.resetCounter();
   InstrumentedView.resetCounter();
   ScopedInstrumentedView.resetCounter();
   ViewWithoutAnnotation.resetCounter();
   WithAnnotationRegisteredView.resetCounter();
   SecondUI.resetCounter();
   RootUI.resetCounter();
   RootWithCustomMappingUI.resetCounter();
   UIWithCDIDependentListener.resetCounter();
   UIWithCDISelfListener.resetCounter();
   DependentCDIEventListener.resetCounter();
   DependentCDIEventListener.resetEventCounter();
   ParameterizedNavigationUI.reset();
   NoViewProviderNavigationUI.resetCounter();
   firstWindow.restartBrowser();
 }
 @Test
 public void unsecuredUI() throws MalformedURLException {
   String uri = deriveMappingForUI(UnsecuredUI.class);
   openWindow(uri);
   final String principalName = firstWindow.getText(id("principalName"));
   final String isUserInRole = firstWindow.getText(id("isUserInRole"));
   final String isUserInSomeRole = firstWindow.getText(id("isUserInSomeRole"));
   final String currentRequestNotNull = firstWindow.getText(id("currentRequestNotNull"));
   final String isUserSignedIn = firstWindow.getText(id("isUserSignedIn"));
   final String disabled = firstWindow.getText(id("disabled"));
   try {
     firstWindow.getText(id("invisible"));
     fail("Invisible element should not be accessible");
   } catch (SeleniumException ex) {
   }
   assertFalse(Boolean.parseBoolean(principalName));
   assertFalse(Boolean.parseBoolean(isUserInRole));
   assertFalse(Boolean.parseBoolean(isUserInSomeRole));
   assertTrue(Boolean.parseBoolean(currentRequestNotNull));
   assertFalse(Boolean.parseBoolean(isUserSignedIn));
   assertThat(disabled, is("DisabledLabel"));
 }
 void openWindowNoWait(GrapheneSelenium window, String uri) throws MalformedURLException {
   URL url = new URL(contextPath.toString() + uri);
   window.open(url);
 }