@When("^replace (\\w+)$") public void replace(String name, DataTable table) { name = name.trim(); String text = getVarAsString(name); List<Map<String, String>> list = table.asMaps(String.class, String.class); String replaced = Script.replacePlaceholders(text, list, context); context.vars.put(name, replaced); }
@When("^send malformed lldp packet$") public void sendMalformedLldpPacket() throws Throwable { System.out.println("=====> Send malformed packet"); long current = System.currentTimeMillis(); Client client = ClientBuilder.newClient(new ClientConfig()); Response result = client .target(trafficEndpoint) .path("/send_malformed_packet") .request() .post(null); System.out.println(String.format("======> Response = %s", result.toString())); System.out.println(String.format("======> Send malformed packet Time: %,.3f", getTimeDuration(current))); assertEquals(200, result.getStatus()); }
@When("^client_one does a PUT on (.*?) with (.*?) in zone 1$") public void client_one_does_a_PUT_on_identifier_in_test_zone(final String api, final String identifier) throws Throwable { OAuth2RestTemplate acsTemplate = this.acsZone1Template; try { switch (api) { case "subject": this.privilegeHelper.putSubject(acsTemplate, this.subject, this.acsUrl, this.zone1Headers, this.privilegeHelper.getDefaultAttribute()); break; case "resource": this.privilegeHelper.putResource(acsTemplate, this.resource, this.acsUrl, this.zone1Headers, this.privilegeHelper.getDefaultAttribute()); break; case "policy-set": this.testPolicyName = "single-action-defined-policy-set"; this.policyHelper.createPolicySet("src/test/resources/single-action-defined-policy-set.json", acsTemplate, this.zone1Headers); break; default: Assert.fail("Api " + api + " does not match/is not yet implemented for this test code."); } } catch (HttpClientErrorException e) { Assert.fail("Unable to PUT identifier: " + identifier + " for api: " + api); } }
@When("^an openRtb validator version \"([^\"]*)\" runs validation on given bid request$") public void isValidBidRequest(String version) throws Throwable { getVersion(version); System.out.println("version"+version); System.out.println(openRtbVersion); validator = OpenRtbValidatorFactory.getValidator(OpenRtbInputType.BID_REQUEST, openRtbVersion); result = validator.validate(JsonLoader.fromResource(resource)); logger.info("validation result: " + result); }
@When("^I click on element having (id|name|class|xpath|css) \"([^\"]*)\" and text \"([^\"]*)\"$") public void clickElementHaving(String type, String element, String text) { List<WebElement> webElements = getWebElements(type, element); for (WebElement el : webElements) if (text.trim().equals(el.getText().trim())) click(el); }
@When("^I POST it to the /templates endpoint$") public void iPOSTItToTheTemplatesEndpoint() throws Throwable { try { lastApiResponse = api.createTemplateWithHttpInfo(template); lastApiCallThrewException = false; lastApiException = null; lastStatusCode = lastApiResponse.getStatusCode(); } catch (ApiException e) { lastApiCallThrewException = true; lastApiResponse = null; lastApiException = e; lastStatusCode = lastApiException.getCode(); } }
/** * Logout of JHipsterSampleApp. * * @throws FailureException * if the scenario encounters a functional error. * @throws TechnicalException * is thrown if you have a technical error (format, configuration, datas, ...) in NoraUi. */ @When("I log out of JHIPSTERSAMPLEAPP") public void logOutOfJHipsterSampleApp() throws FailureException, TechnicalException { if (Auth.isConnected()) { getDriver().switchTo().defaultContent(); clickOn(jHipsterSampleAppPage.accountMenu); Context.waitUntil(ExpectedConditions.presenceOfElementLocated(Utilities.getLocator(jHipsterSampleAppPage.signoutMenu))).click(); } }
@When("^I create a new publication$") public void whenICreateANewPublication() throws Throwable { final Publication publication = TestDataFactory.createValidPublication().build(); testDataRepo.setPublication(publication); assertThat("New publication created.", contentPage.newPublication(publication), is(true)); }
@When("^a link is added in the middle$") public void a_link_is_added_in_the_middle() throws Exception { List<IslInfoData> links = LinksUtils.dumpLinks(); IslInfoData middleLink = getMiddleLink(links); String srcSwitch = getSwitchName(middleLink.getPath().get(0).getSwitchId()); String dstSwitch = getSwitchName(middleLink.getPath().get(1).getSwitchId()); assertTrue("Link is not added", LinksUtils.addLink(srcSwitch, dstSwitch)); TimeUnit.SECONDS.sleep(2); }
@When("^flow (.*) creation request with (.*) (\\d+) (\\d+) and (.*) (\\d+) (\\d+) and (\\d+) is successful$") public void successfulFlowCreation(final String flowId, final String sourceSwitch, final int sourcePort, final int sourceVlan, final String destinationSwitch, final int destinationPort, final int destinationVlan, final int bandwidth) throws Exception { flowPayload = new FlowPayload(FlowUtils.getFlowName(flowId), new FlowEndpointPayload(sourceSwitch, sourcePort, sourceVlan), new FlowEndpointPayload(destinationSwitch, destinationPort, destinationVlan), bandwidth, flowId, null); FlowPayload response = FlowUtils.putFlow(flowPayload); assertNotNull(response); response.setLastUpdated(null); assertEquals(flowPayload, response); }
@When("^(?:.*) (?:orders|has ordered) an? (.*)$") public void sheOrdersA(String order) throws Throwable { orderReceipt = customer.placesAnOrderFor(1, order); Serenity.setSessionVariable("orderReceipt").to(orderReceipt); }
@When("^client_two does a PUT on (.*?) with (.*?) in zone (.*?)$") public void client_two_does_a_PUT_on_subject_with_subject_id__in_zone(final String api, final String identifier, final String subdomainSuffix) throws Throwable { HttpHeaders zoneHeaders = ACSTestUtil.httpHeaders(); OAuth2RestTemplate acsTemplate = this.acsZone2Template; zoneHeaders.set(PolicyHelper.PREDIX_ZONE_ID, getZoneName(subdomainSuffix)); try { switch (api) { case "subject": this.privilegeHelper.putSubject(acsTemplate, this.subject, this.acsUrl, zoneHeaders, this.privilegeHelper.getDefaultAttribute()); break; case "resource": this.privilegeHelper.putResource(acsTemplate, this.resource, this.acsUrl, zoneHeaders, this.privilegeHelper.getDefaultAttribute()); break; case "policy-set": this.testPolicyName = "single-action-defined-policy-set"; CreatePolicyStatus s = this.policyHelper.createPolicySet( "src/test/resources/single-action-defined-policy-set.json", acsTemplate, zoneHeaders); Assert.assertEquals(s, CreatePolicyStatus.SUCCESS); break; default: Assert.fail("Api " + api + " does not match/is not yet implemented for this test code."); } } catch (HttpClientErrorException e) { Assert.fail("Unable to PUT identifier: " + identifier + " for api: " + api, e); } }
@When("^she see details about imported extension$") public void importDetails() throws Throwable { //TODO Deeper validation assertThat(techExtensionsImportPage.validate(), is(true)); techExtensionsImportPage.getButton("Import Extension").shouldBe(visible); techExtensionsImportPage.getButton("Cancel").shouldBe(visible); }
@When("^select points for metric \"([^\"]*)\" with tag \"([^\"]*)\" = \"([^\"]*)\" between \"([^\"]*)\" and \"([^\"]*)\"$") public void selectPointsForMetricWithTagBetweenAnd(String metricName, String tagName, String tagValue, String fromTimeString, String toTimeString) throws Throwable { Tag tag = Tag.of(tagName, tagValue); Interval interval = Interval.until(parseTime(toTimeString)).from(parseTime(fromTimeString)); actualMetricsPoints = granularity == null ? pugTSDB.selectMetricsPoints(metricName, interval, tag) : pugTSDB.selectMetricsPoints(metricName, granularity, interval, tag); }
@When("^replace (\\w+).([^\\s]+) = (.+)") public void replace(String name, String token, String value) { name = name.trim(); String text = getVarAsString(name); String replaced = Script.replacePlaceholderText(text, token, value, context); context.vars.put(name, replaced); }
@When("^url \"([^\"]*)\" and title \"([^\"]*)\" and author \"([^\"]*)\" and name \"([^\"]*)\" and description \"([^\"]*)\" are entered$") public void url_and_title_and_author_and_name_and_description_are_entered(String url, String title, String author, String name, String description) throws Throwable { inputLines.add(url); inputLines.add(title); inputLines.add(author); inputLines.add(name); inputLines.add(description); runApp(); }
@When("^I erase garbage value \"(.*)\"$") public void deleteResourceEditorText(final String text) { // Click the first occurrence of the element only final String normalizedText = text.charAt(0) == '"' ? text.substring(1, text.length() - 1) : text; By by = By.xpath("(//pre[contains(@class, 'CodeMirror-line')]//span[text()='" + normalizedText + "'])[1]"); jwalaUi.click(by); jwalaUi.doubleClick(); jwalaUi.sendKeysViaActions(Keys.BACK_SPACE); }
@When("^client_one does a GET on (.*?) with (.*?) in zone 1$") public void client_one_does_a_GET_on_api_with_identifier_in_test_zone_dev(final String api, final String identifier) throws Throwable { OAuth2RestTemplate acsTemplate = this.acsZone1Template; String encodedIdentifier = URLEncoder.encode(identifier, "UTF-8"); URI uri = URI.create(this.acsUrl + ACS_VERSION + "/" + api + "/" + encodedIdentifier); try { switch (api) { case "subject": this.responseEntity = acsTemplate.exchange(uri, HttpMethod.GET, new HttpEntity<>(this.zone1Headers), BaseSubject.class); this.status = this.responseEntity.getStatusCode().value(); break; case "resource": this.responseEntityForResource = acsTemplate.exchange(uri, HttpMethod.GET, new HttpEntity<>(this.zone1Headers), BaseResource.class); this.status = this.responseEntityForResource.getStatusCode().value(); break; case "policy-set": this.policyset = acsTemplate.exchange( this.acsUrl + PolicyHelper.ACS_POLICY_SET_API_PATH + this.testPolicyName, HttpMethod.GET, new HttpEntity<>(this.zone1Headers), PolicySet.class); this.status = this.policyset.getStatusCode().value(); break; default: Assert.fail("Api " + api + " does not match/is not yet implemented for this test code."); } } catch (HttpClientErrorException e) { e.printStackTrace(); Assert.fail("Unable to GET identifier: " + identifier + " for api: " + api); } }
@When("^url \"([^\"]*)\" and title \"([^\"]*)\" and author \"([^\"]*)\" and description \"([^\"]*)\" are entered$") public void url_and_title_and_author_and_description_are_entered(String url, String title, String author, String description) throws Throwable { inputLines.add(url); inputLines.add(title); inputLines.add(author); inputLines.add(description); runApp(); }
@When("^url \"([^\"]*)\" and title \"([^\"]*)\" and podcast name \"([^\"]*)\" and author \"([^\"]*)\" and description \"([^\"]*)\" are entered$") public void url_and_title_and_podcast_name_and_author_and_description(String url, String title, String podcastName, String author, String description) throws Throwable { inputLines.add(url); inputLines.add(title); inputLines.add(podcastName); inputLines.add(author); inputLines.add(description); runApp(); }
@When("^create a Pug instance with storage path null user \"([^\"]*)\" and pass \"([^\"]*)\"$") public void createAPugInstanceWithStoragePathNullUserAndPass(String user, String pass) throws Throwable { try { actualPug = new PugTSDB(null, user, pass); } catch (Exception e) { actualException = e; } }
@When("^author \"([^\"]*)\" and name \"([^\"]*)\" and description \"([^\"]*)\" are entered$") public void author_and_name_and_description_are_entered(String author, String name, String description) throws Throwable { inputLines.add(author); inputLines.add(name); inputLines.add(description); runApp(); }
@When(".*(?:creates|created) a new Live challenge (.+) and an? (.+) task pair") public void creates_new_live_challenge(String challengeName, String taskName) { dashboard = new Dashboard(driver); newChallengePage = dashboard.createNewLiveChallenge(); newTaskPairPage = newChallengePage .submitWithDefaults(challengeName); newTaskPairPage.submitWithDefaults(taskName, challengeName); }
@When("^I launch iOS app$") public void iLaunchIOSApp() throws Throwable { /* Moved the Desired Capability code to Starting steps to have that at one place This method can be changed to do some assertion as shown below */ Assert.assertTrue(appiumDriver.findElementByAccessibilityId("TextField1").isDisplayed()); }
@When("^I click button with id \"([^\"]*)\"$") public void iClickButtonWithText(String buttonID) throws IllegalAccessException, InterruptedException { Thread.sleep(1000); ViewInteraction appCompatButton = onView(withResourceName(buttonID)); appCompatButton.perform(click()); }
@When("^A policy evaluation is requested with any HTTP action$") public void a_policy_evaluation_is_requested_with_any_HTTP_action() throws Throwable { Set<Attribute> subjectAttributes = Collections.emptySet(); this.policyEvaluationResponse = this.policyHelper.sendEvaluationRequest(this.acsAdminRestTemplate, this.zone1Headers, this.policyHelper.createEvalRequest(DEFAULT_ACTION, DEFAULT_SUBJECT_ID, DEFAULT_RESOURCE_IDENTIFIER, subjectAttributes)); }
@When("^soap action( .+)?") public void soapAction(String action) { action = Script.evalKarateExpression(action, context).getAsString(); if (action == null) { action = ""; } request.setHeader("SOAPAction", action); request.setHeader("Content-Type", "text/xml"); method("post"); }
@When("^I try to upload a file of one of the forbidden types:$") public void iTryToUploadAFileOfOneOfTheForbiddenTypes(final DataTable forbiddenExtensions) throws Throwable { final List<Attachment> forbiddenAttachments = forbiddenExtensions.asList(String.class).stream() .map(extension -> FileType.valueOf(extension.toUpperCase())) .map(forbiddenFileType -> TestDataFactory.createAttachmentOfType(forbiddenFileType).build()) .collect(toList()); testDataRepo.setAttachments(forbiddenAttachments); }
@When("^Evaluation request which has the subject attribute role with the value (.*)$") public void evaluationRequestWithSubjectAttribute(final String subjectAttribute) throws Throwable { Set<Attribute> subjectAttributes = new HashSet<Attribute>(); subjectAttributes.add(new Attribute(DEFAULT_ATTRIBUTE_ISSUER, "role", subjectAttribute)); this.policyEvaluationResponse = this.policyHelper.sendEvaluationRequest(this.acsAdminRestTemplate, this.zone1Headers, this.policyHelper.createEvalRequest(DEFAULT_ACTION, DEFAULT_SUBJECT_ID, DEFAULT_RESOURCE_IDENTIFIER, subjectAttributes)); }
@When("^the calculator sums them$") public void the_calculator_sums_them() throws Throwable { String url = String.format("%s/sum?a=%s&b=%s", server, a, b); result = restTemplate.getForObject(url, String.class); }
@When("^I add (\\d+) and (\\d+)$") public void add(int arg1, int arg2) { calc.push(arg1); calc.push(arg2); calc.push("+"); }
@When("^I substract (\\d+) to (\\d+)$") public void substract(int arg1, int arg2) { calc.push(arg1); calc.push(arg2); calc.push("-"); }
@When("^the customer searches for books published between (\\d+) and (\\d+)$") public void setSearchParameters(@Format("yyyy") Date from, @Format("yyyy") Date to) { result = library.findBooks(from, to); }
@When("^eval (.+)") public final void eval(String exp) { Script.evalJsExpression(exp, context); }
@When("^I click header link Login$") public void i_click_header_link_login() throws Throwable { homePage.clickOnHeaderLinkLogin(); }
@When("^I choose to play the elf card$") public void iChooseToPlayTheElfCard() throws Throwable { game.getCurrentPlayer().getBoard().getHand()[3]--; }