如何使用 Vaadin Testbench 显示网格的隐藏列?
How can I show a hidden column of a grid using the Vaadin Testbench?
我正在做一些集成测试,我已经用网格替换了一些表格。此时我默认有一些可见的列,其他列隐藏如下:
column6.setHidable(true);
column6.setHidden(true);
现在我正在尝试做一些集成测试。为了获取网格,我可以使用以下方法(是此视图中存在的唯一网格):
$(GridElement.class).first();
这很好用。但是对于我的测试(使用 Vaadin Testbench),我需要检查网格隐藏列内的一些值。我说的是这个按钮:
我尝试使用 Vaadin 调试控制台获取允许用户 show/hide 列的按钮的名称,但调试控制台只能 select 整个网格元素,不能这个菜单。
我还检查了 GridElement 内部是否存在任何类型的已实现方法,使我可以访问此菜单但没有任何成功。
通常,chrome developer tools (or similar for firefox and 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();
}
}
当然还有实际效果
我正在做一些集成测试,我已经用网格替换了一些表格。此时我默认有一些可见的列,其他列隐藏如下:
column6.setHidable(true);
column6.setHidden(true);
现在我正在尝试做一些集成测试。为了获取网格,我可以使用以下方法(是此视图中存在的唯一网格):
$(GridElement.class).first();
这很好用。但是对于我的测试(使用 Vaadin Testbench),我需要检查网格隐藏列内的一些值。我说的是这个按钮:
我尝试使用 Vaadin 调试控制台获取允许用户 show/hide 列的按钮的名称,但调试控制台只能 select 整个网格元素,不能这个菜单。
我还检查了 GridElement 内部是否存在任何类型的已实现方法,使我可以访问此菜单但没有任何成功。
通常,chrome developer tools (or similar for firefox and 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();
}
}
当然还有实际效果