1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.test.ui

File SkinxTest.java

 

Code metrics

0
30
4
1
114
73
6
0.2
7.5
4
1.5

Classes

Class Line # Actions
SkinxTest 44 30 0% 6 2
0.941176594.1%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.test.ui;
21   
22    import org.apache.commons.lang3.StringUtils;
23    import org.junit.Assert;
24    import org.junit.Before;
25    import org.junit.Rule;
26    import org.junit.Test;
27    import org.openqa.selenium.By;
28    import org.openqa.selenium.TimeoutException;
29    import org.openqa.selenium.WebDriver;
30    import org.openqa.selenium.support.ui.ExpectedCondition;
31    import org.openqa.selenium.support.ui.WebDriverWait;
32    import org.xwiki.test.po.xe.HomePage;
33    import org.xwiki.test.ui.po.FormElement;
34    import org.xwiki.test.ui.po.ViewPage;
35    import org.xwiki.test.ui.po.editor.ObjectEditPage;
36    import org.xwiki.test.ui.po.editor.WikiEditPage;
37   
38    /**
39    * Test Skin Extensions.
40    *
41    * @version $Id: 1da2102d167549235a4bf1dc7e33e907b5bf952a $
42    * @since 4.1
43    */
 
44    public class SkinxTest extends AbstractTest
45    {
46    @Rule
47    public AdminAuthenticationRule adminAuthenticationRule = new AdminAuthenticationRule(getUtil());
48   
49    private static final String SCRIPT = "window.document.title = 'script active';";
50   
 
51  1 toggle @Before
52    public void setUp() throws Exception
53    {
54  1 getUtil().rest().deletePage("Test", "SkinxTest");
55    }
56   
57    /** http://jira.xwiki.org/browse/XWIKI-7913 */
 
58  1 toggle @Test
59    public void testJavascriptExtension()
60    {
61    // Create a doc
62  1 WikiEditPage wep = WikiEditPage.gotoPage("Test", "SkinxTest");
63  1 wep.setContent("this is the content");
64  1 ViewPage vp = wep.clickSaveAndView();
65   
66    // Add an XWikiGroups object
67  1 ObjectEditPage oep = vp.editObjects();
68  1 FormElement objectForm = oep.addObject("XWiki.JavaScriptExtension");
69  1 objectForm.setFieldValue(By.id("XWiki.JavaScriptExtension_0_code"), SCRIPT);
70  1 objectForm.getSelectElement(By.id("XWiki.JavaScriptExtension_0_use")).select("always");
71  1 oep.clickSaveAndView();
72  1 waitForScriptResult();
73  1 HomePage.gotoPage();
74  1 waitForScriptResult();
75   
76  1 oep = ObjectEditPage.gotoPage("Test", "SkinxTest");
77  1 objectForm = oep.getObjectsOfClass("XWiki.JavaScriptExtension").get(0);
78  1 objectForm.getSelectElement(By.id("XWiki.JavaScriptExtension_0_use")).select("currentPage");
79  1 oep.clickSaveAndView();
80  1 waitForScriptResult();
81  1 HomePage.gotoPage();
82  1 try {
83  1 waitForScriptResult();
84  0 Assert.fail("The JSX should be active only on the current page.");
85    } catch (TimeoutException e) {
86    }
87   
88  1 oep = ObjectEditPage.gotoPage("Test", "SkinxTest");
89  1 objectForm = oep.getObjectsOfClass("XWiki.JavaScriptExtension").get(0);
90  1 objectForm.getSelectElement(By.id("XWiki.JavaScriptExtension_0_use")).select("onDemand");
91  1 oep.clickSaveAndView();
92  1 try {
93  1 waitForScriptResult();
94  0 Assert.fail("The JSX should be active only on demand.");
95    } catch (TimeoutException e) {
96    }
97    }
98   
99    /**
100    * We need to wait for the script result, especially after clicking Save & View (looks like Selenium is not always
101    * waiting for the scripts to be loaded).
102    */
 
103  5 toggle private void waitForScriptResult()
104    {
105  5 new WebDriverWait(getDriver(), getDriver().getTimeout()).until(new ExpectedCondition<Boolean>()
106    {
 
107  45 toggle @Override
108    public Boolean apply(WebDriver driver)
109    {
110  45 return StringUtils.equals("script active", driver.getTitle());
111    }
112    });
113    }
114    }