Project

General

Profile

« Previous | Next » 

Revision 08dde2eb

Added by Andreas Kohlbecker about 5 years ago

ref #8048 implementing page object, element objects & tests for registration page

View differences:

src/main/java/eu/etaxonomy/dataportal/elements/RegistrationItem.java
1
/**
2
* Copyright (C) 2019 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.dataportal.elements;
10

  
11
import java.util.List;
12

  
13
import org.openqa.selenium.By;
14
import org.openqa.selenium.WebElement;
15

  
16
/**
17
 * @author a.kohlbecker
18
 * @since Feb 4, 2019
19
 *
20
 */
21
abstract public class RegistrationItem extends BaseElement {
22

  
23
    enum Style {
24
        /**
25
         * style produced by modules/cdm_dataportal/includes/name.inc#compose_registration_dto_full()
26
         */
27
        FULL,
28
        /**
29
         * style produced by modules/cdm_dataportal/includes/name.inc#compose_registration_dto_compact()
30
         */
31
        COMPACT
32
    }
33

  
34
    protected Style style = null;
35
    protected List<WebElement> specimenTypeDesignations;
36
    protected List<WebElement> nameTypeDesignations;
37
    protected WebElement citation;
38
    protected WebElement metadata;
39
    protected WebElement identifier;
40
    protected WebElement nameElement;
41
    protected WebElement summaryElement;
42

  
43
    /**"
44
     * @param element
45
     */
46
    protected RegistrationItem(WebElement containerElement) {
47
        super(containerElement);
48

  
49
        try {
50
            summaryElement = containerElement.findElement(By.cssSelector(".registration-summary"));
51
            style = Style.COMPACT;
52
            identifier = containerElement.findElement(By.cssSelector(".identifier"));
53
        } catch (Exception e) {
54
            logger.debug("web element .registration-summary not found, now trying full style elements");
55
        }
56

  
57
        if(style == null){
58
            try {
59
                nameElement = containerElement.findElement(By.cssSelector(".name"));
60
            } catch (Exception e) { /* IGNORE */}
61
            try{
62
                specimenTypeDesignations = containerElement.findElements(By.cssSelector(".specimen_type_designation"));
63
            } catch (Exception e) { /* IGNORE */}
64
            try {
65
                nameTypeDesignations = containerElement.findElements(By.cssSelector(".name_type_designation"));
66
            } catch (Exception e) { /* IGNORE */}
67
            try {
68
                citation = containerElement.findElement(By.cssSelector(".citation"));
69
                style = Style.FULL;
70
            } catch (Exception e) { /* IGNORE */}
71

  
72

  
73
        }
74
        // now the general elements which must exist
75
        metadata = containerElement.findElement(By.cssSelector(".registration-date-and-institute"));
76
    }
77

  
78

  
79
    public Style getStyle() {
80
        return style;
81
    }
82

  
83
    public WebElement getMetadata() {
84
        return metadata;
85
    }
86

  
87
    public WebElement getIdentifier() {
88
        return identifier;
89
    }
90

  
91

  
92

  
93
}
src/main/java/eu/etaxonomy/dataportal/elements/RegistrationItemCompact.java
1
/**
2
* Copyright (C) 2019 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.dataportal.elements;
10

  
11
import java.util.Objects;
12

  
13
import org.openqa.selenium.NoSuchElementException;
14
import org.openqa.selenium.WebElement;
15

  
16
public class RegistrationItemCompact extends RegistrationItem{
17

  
18
    /**
19
     * @param containerElement
20
     */
21
    public RegistrationItemCompact(WebElement containerElement) {
22
        super(containerElement);
23
        if(style != style.COMPACT){
24
            throw new NoSuchElementException("RegistrationItem has not the expected style, expected : FULL, but was " + Objects.toString(style, "NULL"));
25
        }
26
    }
27

  
28
    public WebElement getSummaryElement() {
29
        return summaryElement;
30
    }
31

  
32
}
src/main/java/eu/etaxonomy/dataportal/elements/RegistrationItemFull.java
1
/**
2
* Copyright (C) 2019 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.dataportal.elements;
10

  
11
import java.util.List;
12
import java.util.Objects;
13

  
14
import org.openqa.selenium.NoSuchElementException;
15
import org.openqa.selenium.WebElement;
16

  
17
public class RegistrationItemFull extends RegistrationItem{
18

  
19
    /**
20
     * @param containerElement
21
     */
22
    public RegistrationItemFull(WebElement containerElement) {
23
        super(containerElement);
24
        if(style != style.FULL){
25
            throw new NoSuchElementException("RegistrationItem has not the expected style, expected : FULL, but was " + Objects.toString(style, "NULL"));
26
        }
27
    }
28

  
29
    public WebElement getNameElement() {
30
        return nameElement;
31
    }
32

  
33
    public List<WebElement> getSpecimenTypeDesignations() {
34
        return specimenTypeDesignations;
35
    }
36

  
37
    public List<WebElement> getNameTypeDesignations() {
38
        return nameTypeDesignations;
39
    }
40

  
41
    public WebElement getCitation() {
42
        return citation;
43
    }
44
}
src/main/java/eu/etaxonomy/dataportal/pages/PortalPage.java
1 1
package eu.etaxonomy.dataportal.pages;
2 2

  
3
import static org.junit.Assert.assertNull;
4 3
import static org.junit.Assert.assertTrue;
5 4

  
6 5
import java.io.File;
......
42 41
 * @author a.kohlbecker
43 42
 *
44 43
 */
45
public abstract class  PortalPage {
44
public abstract class PortalPage {
46 45

  
47 46
    /**
48 47
     *
......
53 52

  
54 53
    protected final static String DRUPAL_PAGE_QUERY_BASE = "?q=";
55 54

  
55
    public enum MessageType {status, warning, error} // needs to be lowercase
56

  
56 57
    protected WebDriver driver;
57 58

  
58 59
    protected DataPortalContext context;
......
100 101
    @CacheLookup
101 102
    protected WebElement classificationBrowserBlock;
102 103

  
103
//    @FindBys({
104
//        @FindBy(className="messages"),
105
//        @FindBy(className="error")}
106
//        )
107 104
    @FindBy(className="messages")
108 105
    @CacheLookup
109
    protected WebElement messagesErrorCichorieaeTheme;
110

  
111
    @FindBy(className="messages_error")
112
    @CacheLookup
113
    protected WebElement messagesErrorOtherThemes;
106
    protected List<WebElement> messages;
114 107

  
115 108
    /**
116 109
     * Creates a new PortaPage. Implementations of this class will provide the base path of the page by
......
146 139
        logger.info("loading " + pageUrl);
147 140

  
148 141
        try {
149
            assertTrue("The page must not show an error box", !messagesErrorCichorieaeTheme.getAttribute("class").contains("error") && messagesErrorCichorieaeTheme.getText() == null);
150
        } catch (NoSuchElementException e) {
151
            //IGNORE since this is expected!
152
        }
153
        try {
154
            assertNull("The page must not show an error box", messagesErrorOtherThemes.getText());
142
            assertTrue("The page must not show an error box", getErrors() == null);
155 143
        } catch (NoSuchElementException e) {
156 144
            //IGNORE since this is expected!
157 145
        }
......
263 251
        return driver.getTitle();
264 252
    }
265 253

  
254
    public String getMessages(MessageType messageType){
255
        if(messages != null){
256
            for(WebElement m : messages){
257
                if(m.getAttribute("class").contains(messageType.name())){
258
                    return m.getText();
259
                }
260
            }
261
        }
262
        return null;
263
    }
264

  
266 265
    /**
267 266
     * @return the warning messages from the Drupal message box
268 267
     */
269 268
    public String getWarnings() {
270
        return null; //TODO unimplemented
269
        return getMessages(MessageType.warning);
271 270
    }
272 271

  
273 272
    /**
274 273
     * @return the error messages from the Drupal message box
275 274
     */
276 275
    public String getErrors() {
277
        return null; //TODO unimplemented
276
        return getMessages(MessageType.error);
278 277
    }
279 278

  
280 279
    public String getAuthorInformationText() {
src/main/java/eu/etaxonomy/dataportal/pages/RegistrationPage.java
1
/**
2
* Copyright (C) 2019 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.dataportal.pages;
10

  
11
import java.io.UnsupportedEncodingException;
12
import java.net.MalformedURLException;
13
import java.net.URLEncoder;
14
import java.util.UUID;
15

  
16
import org.apache.log4j.Logger;
17
import org.openqa.selenium.WebDriver;
18
import org.openqa.selenium.WebElement;
19
import org.openqa.selenium.support.CacheLookup;
20
import org.openqa.selenium.support.FindBy;
21

  
22
import eu.etaxonomy.dataportal.DataPortalContext;
23
import eu.etaxonomy.dataportal.elements.RegistrationItemFull;
24

  
25
/**
26
 * @author a.kohlbecker
27
 * @since Feb 4, 2019
28
 *
29
 */
30
public class RegistrationPage extends PortalPage {
31

  
32

  
33
    public static final Logger logger = Logger.getLogger(TaxonProfilePage.class);
34

  
35
    private UUID registrationUuid;
36

  
37
    protected static String drupalPagePathBase = "cdm_dataportal/registration";
38

  
39
    @FindBy(id = "registration")
40
    @CacheLookup
41
    private WebElement registrationElement;
42

  
43
    private RegistrationItemFull registrationItem;
44

  
45
    /**
46
     * @param driver
47
     * @param context
48
     * @throws Exception
49
     */
50
    public RegistrationPage(WebDriver driver, DataPortalContext context) throws Exception {
51
        super(driver, context);
52
    }
53

  
54

  
55
    public RegistrationPage(WebDriver driver, DataPortalContext context, String httpID) throws MalformedURLException, UnsupportedEncodingException {
56
        super(driver, context, URLEncoder.encode(URLEncoder.encode(httpID, "UTF-8")));
57
    }
58

  
59
    /**
60
     * {@inheritDoc}
61
     */
62
    @Override
63
    protected String getDrupalPageBase() {
64
        return drupalPagePathBase;
65
    }
66

  
67
    /**
68
     * @return the registrationItem
69
     */
70
    public RegistrationItemFull getRegistrationItem() {
71

  
72
        if(registrationItem == null){
73
            registrationItem = new RegistrationItemFull(registrationElement);
74
        }
75
        return registrationItem;
76
    }
77

  
78

  
79

  
80

  
81

  
82

  
83

  
84
}
src/test/java/eu/etaxonomy/dataportal/selenium/tests/reference/RegistrationPageTest.java
1
/**
2
* Copyright (C) 2019 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.dataportal.selenium.tests.reference;
10

  
11
import java.io.UnsupportedEncodingException;
12
import java.net.MalformedURLException;
13

  
14
import org.junit.Before;
15
import org.junit.Test;
16
import org.openqa.selenium.NoSuchElementException;
17

  
18
import eu.etaxonomy.dataportal.DataPortalSite;
19
import eu.etaxonomy.dataportal.elements.RegistrationItemFull;
20
import eu.etaxonomy.dataportal.junit.CdmDataPortalTestBase;
21
import eu.etaxonomy.dataportal.junit.DataPortalContextSuite.DataPortalContexts;
22
import eu.etaxonomy.dataportal.pages.PortalPage.MessageType;
23
import eu.etaxonomy.dataportal.pages.RegistrationPage;
24

  
25
/**
26
 * @author a.kohlbecker
27
 * @since Feb 5, 2019
28
 *
29
 */
30
@DataPortalContexts( { DataPortalSite.reference })
31
public class RegistrationPageTest extends CdmDataPortalTestBase {
32

  
33
    private static final String planothidium_victori_id = "http://testbank.org/100001";
34

  
35
    private static final String planothidium_victori_epitype_id = "http://testbank.org/100002";
36

  
37
    private static final String nodosilinea_id = "http://testbank.org/100003"; // in preparation!
38

  
39
    private static final String nodosilinea_radiophila_id = "http://testbank.org/100004";
40

  
41
    private static final String ramsaria_id = "http://testbank.org/100005";
42

  
43
    private static final String ramsaria_avicennae_id = "http://testbank.org/100006";
44

  
45
    String titleSuffix = " | Integration test reference";
46

  
47

  
48

  
49
    @Before
50
    public void setUp() throws Exception {
51
        driver.get(getContext().getBaseUri().toString());
52
    }
53

  
54

  
55
    @Test
56
    public void test100001() throws MalformedURLException, UnsupportedEncodingException{
57

  
58
        RegistrationPage p = new RegistrationPage(driver, getContext(), planothidium_victori_id);
59

  
60
        assertEquals("Registration Id: http://testbank.org/100001" + titleSuffix, driver.getTitle());
61
        RegistrationItemFull regItem = p.getRegistrationItem();
62
        assertNotNull(regItem);
63
        assertEquals("Planothidium victori Braidwood, J. & Kilroy, C. in Phytotaxa 64. 2012", regItem.getNameElement().getText());
64
        assertEquals("Braidwood, J. & Kilroy, C., Small diatoms (Bacillariophyta) in cultures from the Styx River, New Zealand, including descriptions of three new species. in Phytotaxa 64: 11-45. 2012", regItem.getCitation().getText());
65
        assertEquals("Registration on 2019-02-04 18:01:53", regItem.getMetadata().getText());
66
    }
67

  
68
    @Test
69
    public void test100002() throws MalformedURLException, UnsupportedEncodingException{
70

  
71
        RegistrationPage p = new RegistrationPage(driver, getContext(), planothidium_victori_epitype_id);
72

  
73
        assertEquals("Registration Id: http://testbank.org/100002" + titleSuffix, driver.getTitle());
74
        RegistrationItemFull regItem = p.getRegistrationItem();
75
        assertNotNull(regItem);
76
        assertEquals("Epitype: (B 40 0040871).", regItem.getSpecimenTypeDesignations().get(0).getText());
77
        assertEquals("Jahn, R, Abarca, N, Gemeinholzer, B & al., Planothidium lanceolatum and Planothicium frequentissimum reinvestigated wieht molecular methods and morphology: four new species and the taxonomic importance of the sinus and cavum in Diatom Research 32: 75-107. 2017", regItem.getCitation().getText());
78
        assertEquals("Registration on 2019-02-05 15:18:16", regItem.getMetadata().getText());
79
    }
80

  
81
    @Test
82
    public void test100003() throws MalformedURLException, UnsupportedEncodingException{
83

  
84
        RegistrationPage p = new RegistrationPage(driver, getContext(), nodosilinea_id);
85

  
86
        assertEquals("Registration in preparation" + titleSuffix, driver.getTitle());
87
        RegistrationItemFull regItem = null;
88
        try {
89
            regItem = p.getRegistrationItem();
90
        } catch(NoSuchElementException e) {/* IGNORE */}
91
        assertNull(regItem);
92

  
93
        assertEquals("Status message\nA registration with the identifier http://testbank.org/100003 is in preparation", p.getMessages(MessageType.status));
94
    }
95

  
96

  
97
    @Test
98
    public void test100004() throws MalformedURLException, UnsupportedEncodingException{
99

  
100
        RegistrationPage p = new RegistrationPage(driver, getContext(), nodosilinea_radiophila_id);
101

  
102
        assertEquals("Registration Id: http://testbank.org/100004" + titleSuffix, driver.getTitle());
103
        RegistrationItemFull regItem = p.getRegistrationItem();
104
        assertNotNull(regItem);
105
        assertEquals("Nodosilinea radiophila Heidari, F., Zima, J., Riahi, H. & Hauer, T. in Fottea 18(2): 142. fig. 5C, D. 1.11.2018", regItem.getNameElement().getText());
106
        assertEquals("Holotype: (CBFS A–83–1).", regItem.getSpecimenTypeDesignations().get(0).getText());
107
        assertEquals("Heidari, F., Zima, J., Riahi, H. & al., New simple trichal cyanobacterial taxa isolated from radioactive thermal springs in Fottea 18(2): 137–149. 2018: 142. fig. 5C, D", regItem.getCitation().getText());
108
        assertEquals("Registration on 2019-02-05 15:16:08", regItem.getMetadata().getText());
109
    }
110

  
111
    @Test
112
    public void test100005() throws MalformedURLException, UnsupportedEncodingException{
113

  
114
        RegistrationPage p = new RegistrationPage(driver, getContext(), ramsaria_id);
115

  
116
        assertEquals("Registration Id: http://testbank.org/100005" + titleSuffix, driver.getTitle());
117
        RegistrationItemFull regItem = p.getRegistrationItem();
118
        assertNotNull(regItem);
119
        assertEquals("Ramsaria Heidari, F. & Hauer, T. in Fottea 18(2): 146. 1.11.2018", regItem.getNameElement().getText());
120
        assertEquals("Orig. des.: Ramsaria avicennae Heidari, F. & Hauer, T. Heidari, F. & Hauer, T. - in Heidari, F., Zima, J., Riahi, H. & al., New simple trichal cyanobacterial taxa isolated from radioactive thermal springs in Fottea 18(2): 137–149. 2018:146", regItem.getNameTypeDesignations().get(0).getText());
121
        assertEquals("Heidari, F., Zima, J., Riahi, H. & al., New simple trichal cyanobacterial taxa isolated from radioactive thermal springs in Fottea 18(2): 137–149. 2018", regItem.getCitation().getText());
122
        assertEquals("Registration on 2019-02-05 15:16:14", regItem.getMetadata().getText());
123
    }
124

  
125
    @Test
126
    public void test100006() throws MalformedURLException, UnsupportedEncodingException{
127

  
128
        RegistrationPage p = new RegistrationPage(driver, getContext(), ramsaria_avicennae_id);
129

  
130
        assertEquals("Registration Id: http://testbank.org/100006" + titleSuffix, driver.getTitle());
131
        RegistrationItemFull regItem = p.getRegistrationItem();
132
        assertNotNull(regItem);
133
        assertEquals("Ramsaria avicennae Heidari, F. & Hauer, T. in Fottea 18(2): 146, fig. 3F, G. 1.11.2018", regItem.getNameElement().getText());
134
        assertEquals("Holotype: (CBFS A–087–1).", regItem.getSpecimenTypeDesignations().get(0).getText());
135
        assertEquals("Heidari, F., Zima, J., Riahi, H. & al., New simple trichal cyanobacterial taxa isolated from radioactive thermal springs in Fottea 18(2): 137–149. 2018", regItem.getCitation().getText());
136
        assertEquals("Registration on 2019-02-05 15:16:23", regItem.getMetadata().getText());
137
    }
138

  
139

  
140

  
141

  
142
}

Also available in: Unified diff