SeleniumSteps { @When("^(?:user )?(?:sets?|puts?) text \"([^\"]+)\" to (?:element|input|textfield) with ([^\"]+)=\"([^\"]+)\"$") public void setInput(String text, String property, String value) { runner.run(selenium().browser(browser) .setInput(text) .element(property, value)); }  @Before void before(); @Given("^(?:selenium )?browser \"([^\"]+)\"$") void setBrowser(String id); @Given("^pages$") void pages(DataTable dataTable); @Given("^page \"([^\"]+)\" ([^\\s]+)$") void page(String id, String type); @Given("^page validators") void page_validators(DataTable dataTable); @Given("^page validator ([^\\s]+) ([^\\s]+)$") void page_validator(String id, String type); @When("^(?:user )?starts? browser$") void start(); @When("^(?:user )?stops? browser$") void stop(); @When("^(?:user )?navigates? to \"([^\"]+)\"$") void navigate(String url); @When("^(?:user )?clicks? (?:element|button|link) with ([^\"]+)=\"([^\"]+)\"$") void click(String property, String value); @When("^(?:user )?(?:sets?|puts?) text \"([^\"]+)\" to (?:element|input|textfield) with ([^\"]+)=\"([^\"]+)\"$") void setInput(String text, String property, String value); @When("^(?:user )?(checks?|unchecks?) checkbox with ([^\"]+)=\"([^\"]+)\"$") void checkInput(String type, String property, String value); @Then("^(?:page )?should (?:display|have) (?:element|button|link|input|textfield|form|heading) with (id|name|class-name|link-text|css-selector|tag-name|xpath)=\"([^\"]+)\"$") void should_display(String property, String value); @Then("^(?:page )?should (?:display|have) (?:element|button|link|input|textfield|form|heading) with (id|name|class-name|link-text|css-selector|tag-name|xpath)=\"([^\"]+)\" having$") void should_display(String property, String value, DataTable dataTable); @When("^(?:page )?([^\\s]+) performs ([^\\s]+)$") void page_action(String pageId, String method); @When("^(?:page )?([^\\s]+) performs ([^\\s]+) with arguments$") void page_action_with_arguments(String pageId, String method, DataTable dataTable); @Then("^(?:page )?([^\\s]+) should validate$") void page_should_validate(String pageId); @Then("^(?:page )?([^\\s]+) should validate with ([^\\s]+)$") void page_should_validate_with_validator(String pageId, String validatorId);  }
@Test public void testSetInput() { SeleniumBrowserConfiguration endpointConfiguration = new SeleniumBrowserConfiguration(); when(seleniumBrowser.getName()).thenReturn("seleniumBrowser"); when(seleniumBrowser.getWebDriver()).thenReturn(webDriver); when(seleniumBrowser.getEndpointConfiguration()).thenReturn(endpointConfiguration); WebElement element = Mockito.mock(WebElement.class); when(element.isDisplayed()).thenReturn(true); when(element.isEnabled()).thenReturn(true); when(element.getTagName()).thenReturn("input"); when(webDriver.findElement(any(By.class))).thenReturn(element); steps.setBrowser("seleniumBrowser"); steps.setInput("Hello","id", "foo"); TestCase testCase = runner.getTestCase(); Assert.assertEquals(testCase.getActionCount(), 1L); Assert.assertTrue(testCase.getTestAction(0) instanceof SeleniumAction); SeleniumAction action = (SeleniumAction) testCase.getTestAction(0); Assert.assertEquals(action.getBrowser(), seleniumBrowser); Assert.assertTrue(action instanceof SetInputAction); Assert.assertEquals(((SetInputAction)action).getValue(), "Hello"); Assert.assertEquals(((SetInputAction)action).getProperty(), "id"); Assert.assertEquals(((SetInputAction)action).getPropertyValue(), "foo"); verify(element).clear(); verify(element).sendKeys("Hello"); }