/*
   * If a value is specified for linkPrefix, then a link is generated with linkPrefix + prettyName of the property from
   * the configuration class.
   * linkPrefix = "http://www.xwiki.org/bin/view/Main/"
   * property prettyName = "WebHome"
   * generated link should equal "http://www.xwiki.org/bin/view/Main/WebHome"
   *
   * Tests: XWiki.ConfigurableClass
   */
  @Test
  public void testLabelLinkGeneration() {
    String space = "Main";
    String page = "TestConfigurable";
    createConfigurableApplication(space, page, "TestSection3", true);
    open(space, page, "edit", "editor=object");
    setFieldValue("XWiki.ConfigurableClass_0_linkPrefix", "TheLinkPrefix");
    clickEditSaveAndView();

    open("XWiki", "XWikiPreferences", "admin", "editor=globaladmin&section=TestSection3");
    assertElementPresent("//form/fieldset//a[@href='TheLinkPrefixString']");
    assertElementPresent("//form/fieldset//a[@href='TheLinkPrefixBoolean']");
    assertElementPresent("//form/fieldset//a[@href='TheLinkPrefixTextArea']");
    assertElementPresent("//form/fieldset//a[@href='TheLinkPrefixSelect']");
  }
  /**
   * Test functionality of the ForgotUsername page:
   *
   * <ul>
   *   <li>A user can be found using correct email
   *   <li>No user is found using wrong email
   *   <li>Email text is properly escaped
   * </ul>
   */
  @Test
  public void testForgotUsername() {
    String space = "Test";
    String page = "SQLTestPage";
    String mail = "*****@*****.**"; // default Admin mail
    String user = "******";
    String badMail = "*****@*****.**";

    // Ensure there is a page we will try to find using HQL injection
    editInWikiEditor(space, page);
    setFieldValue("title", page);
    setFieldValue("content", page);
    clickEditSaveAndView();

    // test that it finds the correct user
    open("XWiki", "ForgotUsername");
    setFieldValue("e", mail);
    submit("//input[@type='submit']"); // there are no other buttons
    assertTextNotPresent("No account is registered using this email address");
    assertElementPresent("//div[@id='xwikicontent']//strong[text()='" + user + "']");

    // test that bad mail results in no results
    open("XWiki", "ForgotUsername");
    setFieldValue("e", badMail);
    submit("//input[@type='submit']"); // there are no other buttons
    assertTextPresent("No account is registered using this email address");
    assertElementNotPresent("//div[@id='xwikicontent']//strong[@value='" + user + "']");

    // XWIKI-4920 test that the email is properly escaped
    open("XWiki", "ForgotUsername");
    setFieldValue("e", "a' synta\\'x error");
    submit("//input[@type='submit']"); // there are no other buttons
    assertTextPresent("No account is registered using this email address");
    assertTextNotPresent("Error");
  }
 /*
  * Test modifying XWiki.XWikiPreferences multi-language field and save it.
  */
 @Test
 public void testSettingXWikiPreferences() {
   clickAdministerWiki();
   clickLinkWithXPath("//a[text()='Localization']", true);
   getSelenium().select("//select[@name='XWiki.XWikiPreferences_0_multilingual']", "label=Yes");
   clickLinkWithXPath("//input[@value='Save']", true);
   assertElementPresent("//a[@id='tmLanguages']");
 }
Пример #4
0
  @Test
  public void testLogin() {
    beginAt("/default.jsp"); // Open the browser on
    // http://localhost:8080/test/home.xhtml

    assertTitleEquals("Movies");
    assertElementPresent("janrainModal");
    String element = getElementAttributeByXPath("//div[@id='janrainModal']", "style");
    assertTrue(element.contains("display: none"));
    clickLink("login");
    element = getElementAttributeByXPath("//div[@id='janrainModal']", "style");
    assertTrue(element.contains("display: block"));

    assertElementPresent("janrain-yahoo");
    clickElementByXPath("//li[@id='janrain-yahoo']");
    assertWindowCountEquals(2);
    assertWindowPresentWithTitle("Sign in to Yahoo!");
    gotoWindowByTitle("Sign in to Yahoo!");
    setTextField("login", "*****@*****.**");
    setTextField("passwd", "Test12345");

    submit(".save");

    try {
      Thread.sleep(20000);
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    // beginAt("/default.jsp");
    // gotoWindowByTitle("Movies");

    assertTextPresent("Logout");
    assertElementPresent("username");
    IElement username = getElementById("username");

    assertTrue(username.getTextContent().contains("movie hunter"));

    assertElementNotPresent("login");

    assertElementPresent("logout");
    clickLink("logout");
    assertElementPresent("login");
  }
Пример #5
0
  /** Test parent, child methods */
  @Test
  public void testChildrenAndParent() {
    assertElementPresent("first");
    IElement element = getElementById("first");
    assertEquals(element.getName(), "li");
    assertEquals(element.getTextContent(), "one");
    assertEquals(element.getAttribute("id"), "first");

    // parent should be an <ol>
    IElement parent = element.getParent();
    assertEquals(parent.getName(), "ol");

    // it should have four children
    List<IElement> children = parent.getChildren();
    assertEquals(children.size(), 4);
    assertEquals(children.get(0).getTextContent(), "one");
    assertEquals(children.get(1).getTextContent(), "two");
    assertEquals(children.get(2).getTextContent(), "three");
    assertEquals(children.get(3).getTextContent(), "four");

    // they are all <li>'s
    for (IElement e : children) assertEquals(e.getName(), "li");
  }
  /*
   * Test Panel Wizard
   */
  @Test
  public void testPanelsAdmin() {
    open("XWiki", "XWikiPreferences", "admin");

    // test panel wizard at global level
    clickLinkWithLocator("//a[text()='Panel Wizard']");
    waitForBodyContains("Page Layout");
    clickLinkWithXPath("//a[@href='#PageLayoutSection']", false);
    waitForElement("//div[@id = 'rightcolumn']");
    clickLinkWithXPath("//div[@id='rightcolumn']", false);
    waitForBodyContains("Panel List");
    clickLinkWithXPath("//a[@href='#PanelListSection']", false);
    dragAndDrop(
        By.xpath("//div[@class='panel expanded CategoriesPanel']//h1"), By.id("rightPanels"));
    assertElementPresent("//div[@id = 'rightPanels']/div[contains(@class, 'CategoriesPanel')]");
    clickLinkWithXPath("//button[text()='Save the new layout']", false);
    waitForNotificationSuccessMessage("The layout has been saved properly.");
    open("Main", "WebHome");
    assertElementNotPresent("leftPanels");
    assertElementPresent("rightPanels");
    assertElementPresent("//div[@id = 'rightPanels']/div[contains(@class, 'CategoriesPanel')]");

    // Revert changes
    open("XWiki", "XWikiPreferences", "admin");
    clickLinkWithLocator("//a[text()='Panel Wizard']");
    waitForBodyContains("Page Layout");
    clickLinkWithXPath("//a[@href='#PageLayoutSection']", false);
    waitForCondition("selenium.isElementPresent(\"//div[@id='bothcolumns']\")!=false;");
    clickLinkWithXPath("//div[@id='bothcolumns']", false);
    waitForBodyContains("Panel List");
    clickLinkWithXPath("//a[@href='#PanelListSection']", false);
    dragAndDrop(
        By.xpath("//div[@id='rightPanels']//div[contains(@class, 'CategoriesPanel')]//h1"),
        By.xpath("//div[@id='allviewpanels']//div[@class='accordionTabContentBox']"));
    assertElementNotPresent("//div[@id = 'rightPanels']//div[contains(@class, 'CategoriesPanel')]");
    clickLinkWithXPath("//button[text()='Save the new layout']", false);
    waitForNotificationSuccessMessage("The layout has been saved properly.");
    open("Main", "WebHome");
    assertElementPresent("leftPanels");
    assertElementPresent("rightPanels");
    assertElementNotPresent("//div[@id = 'rightPanels']//div[contains(@class, 'CategoriesPanel')]");

    // test panel wizard at space level
    open("TestPanelsAdmin", "WebHome", "edit", "editor=wiki");
    setFieldValue("content", "aaa");
    clickEditSaveAndView();
    open("TestPanelsAdmin", "WebPreferences", "admin");
    clickLinkWithLocator("//a[text()='Panel Wizard']");
    waitForBodyContains("Page Layout");
    clickLinkWithXPath("//a[@href='#PageLayoutSection']", false);
    waitForCondition("selenium.isElementPresent(\"//div[@id='leftcolumn']\")!=false;");
    clickLinkWithXPath("//div[@id='leftcolumn']", false);
    waitForBodyContains("Panel List");
    clickLinkWithXPath("//a[@href='#PanelListSection']", false);
    dragAndDrop(
        By.xpath("//div[@class='panel expanded CategoriesPanel']//h1"), By.id("leftPanels"));
    clickLinkWithXPath("//button[text()='Save the new layout']", false);
    waitForNotificationSuccessMessage("The layout has been saved properly.");
    open("TestPanelsAdmin", "WebHome");
    assertElementPresent("leftPanels");
    assertElementPresent("//div[@id = 'leftPanels']//div[contains(@class, 'CategoriesPanel')]");
    open("XWiki", "WebHome");
    assertElementPresent("rightPanels");
    assertElementNotPresent("//div[@id = 'leftPanels']//div[contains(@class, 'CategoriesPanel')]");
  }
 /**
  * Will fail unless it detects a configuration of the type created by
  * createConfigurableApplication.<br>
  * Tests: XWiki.ConfigurableClass
  */
 public void assertConfigurationPresent(String space, String page) {
   assertElementPresent("//div[@id='admin-page-content']/h2[@id='HSomeHeading']/span");
   // Fields
   String fullName = space + "." + page;
   String form =
       "//div[@id='admin-page-content']/form[@action='/xwiki/bin/save/"
           + space
           + "/"
           + page
           + "']";
   assertElementPresent(form + "/fieldset/dl/dt[1]/label");
   assertElementPresent(form + "/fieldset/dl/dd[1]/input[@name='" + fullName + "_0_String']");
   assertElementPresent(form + "/fieldset/dl/dt[2]/label");
   assertElementPresent(form + "/fieldset/dl/dd[2]/select[@name='" + fullName + "_0_Boolean']");
   assertElementPresent(form + "/fieldset/dl/dt[3]/label");
   assertElementPresent(form + "/fieldset/dl/dd[3]/textarea[@name='" + fullName + "_0_TextArea']");
   assertElementPresent(form + "/fieldset/dl/dt[4]/label");
   assertElementPresent(form + "/fieldset/dl/dd[4]/select[@name='" + fullName + "_0_Select']");
   assertElementPresent(form + "/fieldset/input[@id='" + fullName + "_redirect']");
   assertElementPresent(
       form + "/fieldset/input[@value='" + getSelenium().getLocation() + "'][@name='xredirect']");
   // JavaScript injects a save button outside of the form and removes the default save button.
   waitForElement("//*[@class = 'admin-buttons']//input[@type = 'submit' and @value = 'Save']");
 }
  /*
   * Creates a document with 2 configurable objects, one gets configured globally in one section and displays
   * 2 configuration fields, the other is configured in the space in another section and displays the other 2
   * fields. Fails if they are not displayed as they should be.
   *
   * Tests: XWiki.ConfigurableClass
   */
  @Test
  public void testApplicationConfiguredInMultipleSections() {
    String space = "Main";
    String page = "TestConfigurable";

    createConfigurableApplication(space, page, "TestSection1", true);
    open(space, page, "edit", "editor=object");
    // Add a second configurable object.
    getSelenium().select("classname", "value=XWiki.ConfigurableClass");
    clickButtonAndContinue("//input[@name='action_objectadd']");
    setFieldValue("XWiki.ConfigurableClass_1_displayInSection", "TestSection2");
    setFieldValue("XWiki.ConfigurableClass_1_heading", "Some Other Heading");
    setFieldValue("XWiki.ConfigurableClass_1_configurationClass", space + "." + page);
    getSelenium().uncheck("XWiki.ConfigurableClass_1_configureGlobally");
    // Set propertiesToShow so that each config only shows half of the properties.
    setFieldValue("XWiki.ConfigurableClass_1_propertiesToShow", "TextArea, Select");
    setFieldValue("XWiki.ConfigurableClass_0_propertiesToShow", "String, Boolean");
    clickEditSaveAndView();

    // Assert that half of the configuration shows up but not the other half.
    open("XWiki", "XWikiPreferences", "admin", "editor=globaladmin&section=TestSection1");
    assertElementPresent("//div[@id='admin-page-content']/h2[@id='HSomeHeading']/span");
    // Fields
    String fullName = space + "." + page;
    String form =
        "//div[@id='admin-page-content']/form[@action='/xwiki/bin/save/"
            + space
            + "/"
            + page
            + "']";
    assertElementPresent(form + "/fieldset//label['String']");
    assertElementPresent(form + "/fieldset//input[@name='" + fullName + "_0_String']");
    assertElementPresent(form + "/fieldset//label['Boolean']");
    assertElementPresent(form + "/fieldset//select[@name='" + fullName + "_0_Boolean']");
    assertElementPresent(form + "/fieldset/input[@id='" + fullName + "_redirect']");
    // xredirect
    assertElementPresent(
        form + "/fieldset/input[@value='" + getSelenium().getLocation() + "'][@name='xredirect']");
    // Save button
    // assertElementPresent(form + "/div/p/span/input[@type='submit']");
    // Javascript injects a save button outside of the form and removes the default save button.
    waitForElement("//div/div/p/span/input[@type='submit'][@value='Save']");
    // Should not be here
    assertElementNotPresent(form + "/fieldset//textarea[@name='" + fullName + "_0_TextArea']");
    assertElementNotPresent(form + "/fieldset//select[@name='" + fullName + "_0_Select']");

    // Now we go to where the other half of the configuration should be.
    open("Main", "WebPreferences", "admin", "editor=spaceadmin&section=TestSection2");
    assertElementPresent("//h2[@id='HSomeOtherHeading']/span");
    // Fields
    assertElementPresent(form + "/fieldset//label");
    assertElementPresent(form + "/fieldset//textarea[@name='" + fullName + "_0_TextArea']");
    assertElementPresent(form + "/fieldset//select[@name='" + fullName + "_0_Select']");
    assertElementPresent(form + "/fieldset/input[@id='" + fullName + "_redirect']");
    // xredirect
    assertElementPresent(
        form + "/fieldset/input[@value='" + getSelenium().getLocation() + "'][@name='xredirect']");
    // Save button
    // assertElementPresent(form + "/div/p/span/input[@type='submit']");
    // Javascript injects a save button outside of the form and removes the default save button.
    waitForElement("//div/div/p/span/input[@type='submit'][@value='Save']");
    // Should not be here
    assertElementNotPresent(form + "/fieldset//input[@name='" + fullName + "_0_String']");
    assertElementNotPresent(form + "/fieldset//select[@name='" + fullName + "_0_Boolean']");
  }