CheckInputAction extends FindElementAction { @Override protected void execute(WebElement webElement, SeleniumBrowser browser, TestContext context) { super.execute(webElement, browser, context); if (webElement.isSelected() && !checked) { webElement.click(); } else if (checked && !webElement.isSelected()) { webElement.click(); } } CheckInputAction(Builder builder); boolean isChecked();  }
@Test public void testExecuteCheck() throws Exception { when(webDriver.findElement(any(By.class))).thenReturn(element); when(element.isSelected()).thenReturn(false); CheckInputAction action = new CheckInputAction.Builder() .browser(seleniumBrowser) .element("name", "checkbox") .checked(true) .build(); action.execute(context); verify(element).click(); }
@Test public void testExecuteUncheck() throws Exception { when(webDriver.findElement(any(By.class))).thenReturn(element); when(element.isSelected()).thenReturn(true); CheckInputAction action = new CheckInputAction.Builder() .browser(seleniumBrowser) .element("name", "checkbox") .checked(false) .build(); action.execute(context); verify(element).click(); }
@Test public void testExecuteAlreadyChecked() throws Exception { when(webDriver.findElement(any(By.class))).thenReturn(element); when(element.isSelected()).thenReturn(true); CheckInputAction action = new CheckInputAction.Builder() .browser(seleniumBrowser) .element("name", "checkbox") .checked(true) .build(); action.execute(context); verify(element, times(0)).click(); }