You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CheckBoxRpcCountTest.java 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  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, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.components.checkbox;
  17. import static org.junit.Assert.assertEquals;
  18. import com.vaadin.testbench.elements.CheckBoxElement;
  19. import com.vaadin.testbench.elements.LabelElement;
  20. import org.junit.Test;
  21. import org.openqa.selenium.By;
  22. import org.openqa.selenium.WebDriver;
  23. import org.openqa.selenium.WebElement;
  24. import com.vaadin.tests.tb3.MultiBrowserTest;
  25. import org.openqa.selenium.support.ui.ExpectedCondition;
  26. public class CheckBoxRpcCountTest extends MultiBrowserTest {
  27. @Test
  28. public void numberOfRpcCallsIsEqualToClicks() {
  29. openTestURL();
  30. CheckBoxElement checkBoxElement = $(CheckBoxElement.class).first();
  31. WebElement labelElem = checkBoxElement.findElement(By.tagName("label"));
  32. WebElement inputElem = checkBoxElement.findElement(By.tagName("input"));
  33. final WebElement countElem = $(LabelElement.class).id("count-label");
  34. // Click on the actual checkbox.
  35. inputElem.click();
  36. // Have to use waitUntil to make this test more stable.
  37. waitUntilLabelIsUpdated(countElem, "1 RPC call(s) made.");
  38. // Click on the checkbox label.
  39. labelElem.click();
  40. waitUntilLabelIsUpdated(countElem, "2 RPC call(s) made.");
  41. // Again on the label.
  42. labelElem.click();
  43. waitUntilLabelIsUpdated(countElem, "3 RPC call(s) made.");
  44. }
  45. private void waitUntilLabelIsUpdated(final WebElement countElem,
  46. final String expectedText) {
  47. waitUntil(new ExpectedCondition<Boolean>() {
  48. @Override
  49. public Boolean apply(WebDriver input) {
  50. return countElem.getText().equals(expectedText);
  51. }
  52. }, 5);
  53. }
  54. }