View Javadoc

1   /*
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.demo.uif.library.collections;
17  
18  import org.junit.Test;
19  import org.kuali.rice.krad.demo.uif.library.DemoLibraryBase;
20  import org.openqa.selenium.By;
21  import org.openqa.selenium.WebElement;
22  
23  import java.util.List;
24  
25  /**
26   * @author Kuali Rice Team (rice.collab@kuali.org)
27   */
28  public class DemoCollectionSequenceAft extends DemoLibraryBase {
29  
30      /**
31       * /kr-krad/kradsampleapp?viewId=Demo-CollectionSequenceView
32       */
33      public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-CollectionSequenceView";
34  
35      @Override
36      protected String getBookmarkUrl() {
37          return BOOKMARK_URL;
38      }
39  
40      @Override
41      protected void navigate() throws Exception {
42          navigateToLibraryDemo("Collection Features", "Sequence Column");
43      }
44  
45      protected void changeSequenceView() throws Exception {
46      	
47      	//Auto Sequence
48          assert(isOptionSelected("exampleShown", "Demo-CollectionSequence-Example1"));
49          testAutoSequence();
50          
51          //Field Sequence
52          selectOptionByName("exampleShown","Demo-CollectionSequence-Example2");
53          waitForPageToLoad();
54          assert(isOptionSelected("exampleShown", "Demo-CollectionSequence-Example2"));
55          testFieldSequence();
56          
57          //No Sequence
58          selectOptionByName("exampleShown","Demo-CollectionSequence-Example3");
59          waitForPageToLoad();
60          assert(isOptionSelected("exampleShown", "Demo-CollectionSequence-Example3"));
61          testNoSequence();
62      }
63  
64      protected void testCollectionSequenceExamples() throws Exception {
65          changeSequenceView();
66      }
67  
68      private boolean isOptionSelected(String dropDownName, String optionValue) {
69          WebElement select = driver.findElement(By.name(dropDownName));
70          List<WebElement> options = select.findElements(By.tagName("option"));
71          for (WebElement option: options) {
72              if (option.getAttribute("selected")!=null) {
73                  return true;
74              }
75          }
76          return false;
77      }
78      
79      private void testAutoSequence() throws InterruptedException{
80      	for(short i=1; i<10 ; i++)
81      	{
82      		if(i==2)
83      			i++;
84      		waitForElementPresentByXpath("//div[@data-parent='Demo-CollectionSequence-Example1']/div[@class='uif-disclosureContent']/div/table/tbody/tr/td/div/span[contains(text(),'"+i+"')]");
85      	}
86      }
87      
88      private void testFieldSequence() throws InterruptedException{
89      	//Cant test all in loop as the value differs a lot.
90      	waitForElementPresentByXpath("//div[@data-parent='Demo-CollectionSequence-Example2']/div[@class='uif-disclosureContent']/div/table/tbody/tr/td/div/span[contains(text(),'3')]");
91      }
92      
93      private void testNoSequence() throws InterruptedException{
94      	waitForElementNotPresent(By.xpath("//div[@data-parent='Demo-CollectionSequence-Example3']/div[@class='uif-disclosureContent']/div/table/tbody/tr/td/div/span"));
95      }
96  
97      @Test
98      public void testCollectionSequenceBookmark() throws Exception {
99          testCollectionSequenceExamples();
100         passed();
101     }
102 
103     @Test
104     public void testCollectionSequenceNav() throws Exception {
105         testCollectionSequenceExamples();
106         passed();
107     }
108 }