How to use pages method of com.consol.citrus.cucumber.step.runner.selenium.SeleniumSteps class

Best Citrus code snippet using com.consol.citrus.cucumber.step.runner.selenium.SeleniumSteps.pages

Source:SeleniumSteps.java Github

copy

Full Screen

...39 protected TestRunner runner;40 @CitrusFramework41 protected Citrus citrus;42 /** Page objects defined by id */43 private Map<String, WebPage> pages;44 /** Page validators defined by id */45 private Map<String, PageValidator> validators;46 /** Selenium browser */47 protected SeleniumBrowser browser;48 @Before49 public void before(Scenario scenario) {50 if (browser == null && citrus.getApplicationContext().getBeansOfType(SeleniumBrowser.class).size() == 1L) {51 browser = citrus.getApplicationContext().getBean(SeleniumBrowser.class);52 }53 pages = new HashMap<>();54 validators = new HashMap<>();55 }56 @Given("^(?:selenium )?browser \"([^\"]+)\"$")57 public void setBrowser(String id) {58 if (!citrus.getApplicationContext().containsBean(id)) {59 throw new CitrusRuntimeException("Unable to find selenium browser for id: " + id);60 }61 browser = citrus.getApplicationContext().getBean(id, SeleniumBrowser.class);62 }63 @Given("^pages$")64 public void pages(DataTable dataTable) {65 Map<String, String> variables = dataTable.asMap(String.class, String.class);66 for (Map.Entry<String, String> entry : variables.entrySet()) {67 page(entry.getKey(), entry.getValue());68 }69 }70 @Given("^page \"([^\"]+)\" ([^\\s]+)$")71 public void page(String id, String type) {72 try {73 pages.put(id, (WebPage) Class.forName(type).newInstance());74 } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {75 throw new CitrusRuntimeException("Failed to laod page object", e);76 }77 }78 @Given("^page validators")79 public void page_validators(DataTable dataTable) {80 Map<String, String> variables = dataTable.asMap(String.class, String.class);81 for (Map.Entry<String, String> entry : variables.entrySet()) {82 page_validator(entry.getKey(), entry.getValue());83 }84 }85 @Given("^page validator ([^\\s]+) ([^\\s]+)$")86 public void page_validator(String id, String type) {87 try {88 validators.put(id, (PageValidator) Class.forName(type).newInstance());89 } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {90 throw new CitrusRuntimeException("Failed to laod page object", e);91 }92 }93 @When("^(?:user )?starts? browser$")94 public void start() {95 runner.selenium(action ->action.browser(browser)96 .start());97 }98 @When("^(?:user )?stops? browser$")99 public void stop() {100 runner.selenium(action ->action.browser(browser)101 .stop());102 }103 @When("^(?:user )?navigates? to \"([^\"]+)\"$")104 public void navigate(String url) {105 runner.selenium(action ->action.browser(browser)106 .navigate(url));107 }108 @When("^(?:user )?clicks? (?:element|button|link) with ([^\"]+)=\"([^\"]+)\"$")109 public void click(String property, String value) {110 runner.selenium(action ->action.browser(browser)111 .click()112 .element(property, value));113 }114 @When("^(?:user )?(?:sets?|puts?) text \"([^\"]+)\" to (?:element|input|textfield) with ([^\"]+)=\"([^\"]+)\"$")115 public void setInput(String text, String property, String value) {116 runner.selenium(action ->action.browser(browser)117 .setInput(text)118 .element(property, value));119 }120 @When("^(?:user )?(checks?|unchecks?) checkbox with ([^\"]+)=\"([^\"]+)\"$")121 public void checkInput(String type, String property, String value) {122 runner.selenium(action ->action.browser(browser)123 .checkInput(type.equals("check") || type.equals("checks"))124 .element(property, value));125 }126 @Then("^(?:page )?should (?:display|have) (?:element|button|link|input|textfield|form|heading) with (id|name|class-name|link-text|css-selector|tag-name|xpath)=\"([^\"]+)\"$")127 public void should_display(String property, String value) {128 runner.selenium(action ->action.browser(browser)129 .find()130 .enabled(true)131 .displayed(true)132 .element(property, value));133 }134 @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$")135 public void should_display(String property, String value, DataTable dataTable) {136 Map<String, String> elementProperties = dataTable.asMap(String.class, String.class);137 runner.selenium(action -> {138 SeleniumActionBuilder.FindElementActionBuilder elementBuilder = action.browser(browser)139 .find()140 .element(property, value);141 for (Map.Entry<String, String> propertyEntry : elementProperties.entrySet()) {142 if (propertyEntry.getKey().equals("tag-name")) {143 elementBuilder.tagName(propertyEntry.getValue());144 }145 if (propertyEntry.getKey().equals("text")) {146 elementBuilder.text(propertyEntry.getValue());147 }148 if (propertyEntry.getKey().equals("enabled")) {149 elementBuilder.enabled(Boolean.valueOf(propertyEntry.getValue()));150 }151 if (propertyEntry.getKey().equals("displayed")) {152 elementBuilder.displayed(Boolean.valueOf(propertyEntry.getValue()));153 }154 if (propertyEntry.getKey().equals("styles") || propertyEntry.getKey().equals("style")) {155 String[] propertyExpressions = StringUtils.delimitedListToStringArray(propertyEntry.getValue(), ";");156 for (String propertyExpression : propertyExpressions) {157 String[] keyValue = propertyExpression.split("=");158 elementBuilder.style(keyValue[0].trim(), VariableUtils.cutOffDoubleQuotes(keyValue[1].trim()));159 }160 }161 if (propertyEntry.getKey().equals("attributes") || propertyEntry.getKey().equals("attribute")) {162 String[] propertyExpressions = StringUtils.commaDelimitedListToStringArray(propertyEntry.getValue());163 for (String propertyExpression : propertyExpressions) {164 String[] keyValue = propertyExpression.split("=");165 elementBuilder.attribute(keyValue[0].trim(), VariableUtils.cutOffDoubleQuotes(keyValue[1].trim()));166 }167 }168 }169 });170 }171 @When("^(?:page )?([^\\s]+) performs ([^\\s]+)$")172 public void page_action(String pageId, String method) {173 page_action_with_arguments(pageId, method, null);174 }175 @When("^(?:page )?([^\\s]+) performs ([^\\s]+) with arguments$")176 public void page_action_with_arguments(String pageId, String method, DataTable dataTable) {177 verifyPage(pageId);178 runner.selenium(action -> {179 List<String> arguments = new ArrayList<>();180 if (dataTable != null) {181 arguments = dataTable.asList(String.class);182 }183 action.browser(browser)184 .page(pages.get(pageId))185 .execute(method)186 .arguments(arguments);187 });188 }189 @Then("^(?:page )?([^\\s]+) should validate$")190 public void page_should_validate(String pageId) {191 page_should_validate_with_validator(pageId, null);192 }193 @Then("^(?:page )?([^\\s]+) should validate with ([^\\s]+)$")194 public void page_should_validate_with_validator(String pageId, String validatorId) {195 verifyPage(pageId);196 runner.selenium(action -> {197 PageValidator pageValidator = null;198 if (validators.containsKey(validatorId)) {199 pageValidator = validators.get(validatorId);200 }201 action.browser(browser)202 .page(pages.get(pageId))203 .validator(pageValidator)204 .validate();205 });206 }207 /**208 * Verify that page is known.209 * @param pageId210 */211 private void verifyPage(String pageId) {212 if (!pages.containsKey(pageId)) {213 throw new CitrusRuntimeException(String.format("Unknown page '%s' - please introduce page with type information first", pageId));214 }215 }216}...

Full Screen

Full Screen

pages

Using AI Code Generation

copy

Full Screen

1 @When("^I navigate to page (\\d+)$")2 public void navigateToPage(int page) {3 selenium().pages().navigateToPage(page);4 }5 @Then("^I see page (\\d+)$")6 public void seePage(int page) {7 selenium().pages().seePage(page);8 }9 @Then("^I see (\\d+) pages$")10 public void seePages(int pages) {11 selenium().pages().seePages(pages);12 }13}

Full Screen

Full Screen

pages

Using AI Code Generation

copy

Full Screen

1Given I navigate to page '${page}' using selenium2Given I navigate to page '${page}' using selenium3Given I navigate to page '${page}' using selenium4Given I navigate to page '${page}' using selenium5Given I navigate to page '${page}' using selenium6Given I navigate to page '${page}' using selenium7Given I navigate to page '${page}' using selenium8Given I navigate to page '${page}' using selenium9Given I navigate to page '${page}' using selenium10Given I navigate to page '${page}' using selenium11Given I navigate to page '${page}' using selenium12Given I navigate to page '${page}' using selenium13Given I navigate to page '${page}' using selenium

Full Screen

Full Screen

pages

Using AI Code Generation

copy

Full Screen

1@Given("^I have a page object named \"([^\"]*)\"$")2public void iHaveAPageObjectNamed(String pageName) throws Throwable {3 seleniumSteps.pages().createPage(pageName);4}5@Then("^I get the page object named \"([^\"]*)\"$")6public void iGetThePageObjectNamed(String pageName) throws Throwable {7 seleniumSteps.pages().getPage(pageName);8}9@Then("^I get a page object$")10public void iGetAPageObject() throws Throwable {11 seleniumSteps.pages().getPage();12}13@Then("^I get a page object with name \"([^\"]*)\"$")14public void iGetAPageObjectWithName(String pageName) throws Throwable {15 seleniumSteps.pages().getPage(pageName);16}17@Then("^I get a page object with name \"([^\"]*)\" and type \"([^\"]*)\"$")18public void iGetAPageObjectWithNameAndType(String pageName, String pageType) throws Throwable {19 seleniumSteps.pages().getPage(pageName, pageType);20}21@Then("^I get a page object with type \"([^\"]*)\"$")22public void iGetAPageObjectWithType(String pageType) throws Throwable {23 seleniumSteps.pages().getPage(pageType);24}25@Then("^I get a page object with type \"([^\"]*)\" and name \"([^\"]*)\"$")

Full Screen

Full Screen

pages

Using AI Code Generation

copy

Full Screen

1When("I visit the {string} page")2Then("I should see the {string} page")3And("I click on the {string} link")4And("I should see {string} text")5And("I should not see {string} text")6And("I click on the {string} button")7And("I should see {string} text")8And("I should not see {string} text")9And("I click on the {string} button")10And("I should see {string} text")11And("I should not see {string} text")12And("I click on the {string} button")

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Citrus automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful