View Javadoc

1   package com.atlassian.webdriver.jira.page;
2   
3   import com.atlassian.pageobjects.binder.Init;
4   import com.atlassian.webdriver.utils.by.ByJquery;
5   import org.openqa.selenium.By;
6   import org.openqa.selenium.WebElement;
7   import org.openqa.selenium.support.FindBy;
8   
9   import java.util.List;
10  import java.util.regex.Matcher;
11  import java.util.regex.Pattern;
12  
13  /**
14   * 
15   */
16  public class ViewAttachmentsSettingsPage extends JiraAdminAbstractPage
17  {
18  
19      private static final String URI = "/secure/admin/ViewAttachmentSettings.jspa";
20  
21      private static final String ENABLED = "ON";
22  
23      @FindBy (id = "AttachmentSettings")
24      private WebElement attachmentSettingsTable;
25  
26      private boolean attachmentsEnabled;
27      private boolean thumnailsEnabled;
28      private boolean zipSupportEnabled;
29  
30      private String attachmentPath;
31      private String attachmentSize;
32  
33  
34      public String getUrl()
35      {
36          return URI;
37      }
38  
39      @Init
40      public void readAttachmentSettings()
41      {
42  
43          By colLocator = By.cssSelector("td ~ td");
44          List<WebElement> attachSettingsRows = attachmentSettingsTable.findElements(By.tagName("tr"));
45  
46          attachmentsEnabled = attachSettingsRows.get(1).findElement(colLocator).getText().equals(ENABLED);
47  
48          attachmentPath = parseAttachmentPath(attachSettingsRows.get(2).findElement(colLocator).getText());
49          attachmentSize = attachSettingsRows.get(3).findElement(colLocator).getText();
50  
51          thumnailsEnabled = attachSettingsRows.get(4).findElement(colLocator).getText().equals(ENABLED);
52          zipSupportEnabled = attachSettingsRows.get(5).findElement(colLocator).getText().equals(ENABLED);
53  
54      }
55  
56      /**
57       * parses the path to the attachments directory from the attachment path row
58       * @param columnText the text to parse to extract the path
59       * @return the path as a String otherwise the empty string
60       */
61      private String parseAttachmentPath(String columnText)
62      {
63          //Match text inbetween square brackets
64          Pattern p = Pattern.compile("\\[([^\\]]+)\\]");
65          Matcher m = p.matcher(columnText);
66  
67          if (m.find())
68          {
69              return m.group(1);
70          }
71  
72          return "";
73      }
74  
75      public boolean attachmentsAreEnabled()
76      {
77          return attachmentsEnabled;
78      }
79  
80      public boolean thumnailsAreEnabled()
81      {
82          return thumnailsEnabled;
83      }
84  
85      public boolean zipSupportIsEnabled()
86      {
87          return zipSupportEnabled;
88      }
89  
90      public String getAttachmentPath()
91      {
92          return attachmentPath;
93      }
94  
95      public String getAttachmentSize()
96      {
97          return attachmentSize;
98      }
99  }