Commit 6440263645bafed75371720e4609d3bcab62a403

Authored by tomek
1 parent db7146ba

Implemented methods for operations on schedule.

@@ -9,6 +9,7 @@ import com.gargoylesoftware.htmlunit.html.HtmlPage; @@ -9,6 +9,7 @@ import com.gargoylesoftware.htmlunit.html.HtmlPage;
9 import com.gargoylesoftware.htmlunit.html.HtmlSpan; 9 import com.gargoylesoftware.htmlunit.html.HtmlSpan;
10 import com.gargoylesoftware.htmlunit.html.HtmlTable; 10 import com.gargoylesoftware.htmlunit.html.HtmlTable;
11 import com.gargoylesoftware.htmlunit.html.HtmlTableCell; 11 import com.gargoylesoftware.htmlunit.html.HtmlTableCell;
  12 +import com.gargoylesoftware.htmlunit.html.HtmlTableDataCell;
12 import com.gargoylesoftware.htmlunit.html.HtmlTableRow; 13 import com.gargoylesoftware.htmlunit.html.HtmlTableRow;
13 14
14 import java.io.IOException; 15 import java.io.IOException;
@@ -158,12 +159,23 @@ public class WebClientUtils { @@ -158,12 +159,23 @@ public class WebClientUtils {
158 } 159 }
159 160
160 @SuppressWarnings("unchecked") 161 @SuppressWarnings("unchecked")
161 - public static List<String> getScheduleEventTitles(HtmlElement schedule) {  
162 - final List<HtmlSpan> titleElements = (List<HtmlSpan>) schedule.getByXPath(".//*[@class='fc-event-title']");  
163 - List<String> titles = new ArrayList<String>(titleElements.size());  
164 - for (HtmlSpan o : titleElements) {  
165 - titles.add(o.asText());  
166 - }  
167 - return titles; 162 + public static List<HtmlSpan> getScheduleEventTitles(HtmlElement schedule) {
  163 + return (List<HtmlSpan>) schedule.getByXPath(".//*[@class='fc-event-title']");
  164 + }
  165 +
  166 + public static void switchScheduleToNextMonth(HtmlElement schedule) throws IOException {
  167 + ((HtmlElement) schedule.getByXPath(".//*[contains(@class,'fc-button-next')]").get(0)).click();
  168 + }
  169 +
  170 + /**
  171 + * IMPORTANT: Because of bugs in htmlunit and jsfunit which make schedule component render improperly this method should be used only to retrieve
  172 + * cell elements from the first row of schedule grid. Any operations on cell elements from other rows are likely to cause error.
  173 + *
  174 + * @param schedule schedule element
  175 + * @param dayOfMonth number of day of month representing cell you wish to retrieve
  176 + * @return list of schedule cells
  177 + */
  178 + public static HtmlTableDataCell getScheduleDayCell(HtmlElement schedule, int dayOfMonth) {
  179 + return (HtmlTableDataCell) schedule.getByXPath(".//td[contains(@class,'fc-day') and not(contains(@class,'fc-other-month'))]").get(dayOfMonth - 1);
168 } 180 }
169 } 181 }
Please register or login to post a comment