【问题标题】:How can I show a hidden column of a grid using the Vaadin Testbench?如何使用 Vaadin 测试台显示网格的隐藏列?
【发布时间】:2016-07-18 11:04:45
【问题描述】:

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

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

现在我正在尝试做一些集成测试。为了获取网格,我可以使用方法(是此视图中唯一存在的网格):

$(GridElement.class).first();

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

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

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

【问题讨论】:

    标签: vaadin vaadin7


    【解决方案1】:

    通常,chrome developer tools(或类似的firefox 和ie / edge 等)在这种情况下是你最好的朋友。到目前为止,我不知道有任何专门用于该特定按钮的东西。但是,您可以通过按特定类选择构成此功能的项目来解决此限制:

    下面的测试方法显示了一个快速的实现,它应该给你一个起点:

    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();
        }
    }
    

    当然还有实际效果

    【讨论】:

    • 谢谢,非常有用的解释!在 Vaadin 团队创建访问此元素的特定方法之前,这可以正常工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-14
    • 2015-12-27
    相关资源
    最近更新 更多