如何使用Vaadin Testbench显示网格的隐藏列?

时间:2016-07-18 11:04:45

标签: vaadin vaadin7

我正在做一些集成测试,我用网格替换了一些表。此时,默认情况下我有一些可见列,其他列隐藏如下:

column6.setHidable(true);
column6.setHidden(true);

现在我正在尝试进行一些集成测试。为了获得网格,我可以使用该方法(这是该视图中唯一的网格):

$(GridElement.class).first();

这很好用。但是对于我的测试(使用Vaadin Testbench),我需要检查网格隐藏列中的一些值。我在谈论这个按钮:

enter image description here

我尝试使用Vaadin调试控制台获取允许用户显示/隐藏列的按钮名称,但调试控制台只能选择整个网格元素,而不是此菜单。

此外,我还检查GridElement内部是否存在任何已经实现的方法,使我可以访问此菜单但没有任何成功。

1 个答案:

答案 0 :(得分:1)

通常情况下,chrome developer tools(或类似于firefoxie / edge等)是您在这种情况下最好的朋友。到目前为止,我还没有发现任何专用于该特定按钮的内容。但是,您可以通过选择按特定类组成此功能的项目来解决此限制:

chrome developer tools

以下测试方法显示了一个快速实现,它应该为您提供一个起点:

public class GridManipulationTest extends TestBenchTestCase {

    @Before
    public void setUp() throws Exception {
        System.setProperty("webdriver.chrome.driver", "D:\\Kit\\chromedriver_win32\\chromedriver.exe");
        setDriver(new ChromeDriver());
    }

    @After
    public void tearDown() throws Exception {
        // TODO uncomment below after checking all works as expected
        //getDriver().quit();
    }

    @Test
    public void shouldOpenGridColumnVisibilityPopupAndSelectItems() {
        // class for the grid sidebar button
        String sideBarButtonClass = "v-grid-sidebar-button";

        // class for the sidebar content which gets created when the button is clicked
        String sideBarContentClass = "v-grid-sidebar-content";

        // xpath to select the item corresponding to the necessary column
        // there are perhaps more "elegant" solutions, but this is what I came up with at the time
        String columnMenuItemXpath = "//*[contains(@class, 'column-hiding-toggle')]/span/div[text()='Name']";

        // open the browser
        getDriver().get("http://localhost:8080/");

        // get the first available grid
        GridElement firstGrid = $(GridElement.class).first();

        // look for the grid's sidebar button and click it
        firstGrid.findElement((By.className(sideBarButtonClass))).click();

        // the sidebar content is created outside the grid structure so don't look for it using the grid search context
        WebElement sidebarContent = findElement(By.className(sideBarContentClass));

        // look for the expected column name and click it
        sidebarContent.findElement(By.xpath(columnMenuItemXpath)).click();
    }
}

当然,它在行动中的样子

Testbench grid column menu selection

相关问题