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.

TabSheetFocusedTabTest.java 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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.tabsheet;
  17. import static org.junit.Assert.assertFalse;
  18. import static org.junit.Assert.assertTrue;
  19. import org.junit.Test;
  20. import org.openqa.selenium.Keys;
  21. import org.openqa.selenium.WebElement;
  22. import org.openqa.selenium.interactions.Actions;
  23. import com.vaadin.testbench.By;
  24. import com.vaadin.tests.tb3.MultiBrowserTest;
  25. public class TabSheetFocusedTabTest extends MultiBrowserTest {
  26. @Override
  27. protected Class<?> getUIClass() {
  28. return TabsheetScrolling.class;
  29. }
  30. @Test
  31. public void clickingChangesFocusedTab() throws Exception {
  32. openTestURL();
  33. getTab(1).click();
  34. assertTrue(isFocused(getTab(1)));
  35. new Actions(getDriver()).sendKeys(Keys.RIGHT).perform();
  36. assertFalse(isFocused(getTab(1)));
  37. assertTrue(isFocused(getTab(3)));
  38. getTab(5).click();
  39. assertFalse(isFocused(getTab(3)));
  40. assertTrue(isFocused(getTab(5)));
  41. getTab(1).click();
  42. assertFalse(isFocused(getTab(5)));
  43. assertTrue(isFocused(getTab(1)));
  44. }
  45. private WebElement getTab(int index) {
  46. return getDriver()
  47. .findElement(
  48. By.xpath("(//table[contains(@class, 'v-tabsheet-tabs')])[1]/tbody/tr/td["
  49. + (index + 1) + "]/div"));
  50. }
  51. private boolean isFocused(WebElement tab) {
  52. return tab.getAttribute("class").contains("v-tabsheet-tabitem-focus");
  53. }
  54. }