How to use PageAction method of com.consol.citrus.selenium.actions.PageAction class

Best Citrus code snippet using com.consol.citrus.selenium.actions.PageAction.PageAction

Source:PageActionTest.java Github

copy

Full Screen

...36/**37 * @author Christoph Deppisch38 * @since 2.739 */40public class PageActionTest extends AbstractTestNGUnitTest {41 private SeleniumBrowser seleniumBrowser = new SeleniumBrowser();42 private WebDriver webDriver = Mockito.mock(WebDriver.class);43 private WebElement formElement = Mockito.mock(WebElement.class);44 private WebElement inputElement = Mockito.mock(WebElement.class);45 @BeforeMethod46 public void setup() {47 reset(webDriver, formElement, inputElement);48 seleniumBrowser.setWebDriver(webDriver);49 when(formElement.getTagName()).thenReturn("form");50 when(formElement.isEnabled()).thenReturn(true);51 when(formElement.isDisplayed()).thenReturn(true);52 when(inputElement.getTagName()).thenReturn("input");53 when(inputElement.isEnabled()).thenReturn(true);54 when(inputElement.isDisplayed()).thenReturn(true);55 when(webDriver.findElement(By.id("userForm"))).thenReturn(formElement);56 when(webDriver.findElement(By.id("username"))).thenReturn(inputElement);57 }58 @Test59 public void testExecutePageValidation() throws Exception {60 when(inputElement.getAttribute("value")).thenReturn("TestUser");61 PageAction action = new PageAction.Builder()62 .browser(seleniumBrowser)63 .action("validate")64 .page(new UserFormPage())65 .build();66 action.execute(context);67 }68 @Test69 public void testExecutePageType() throws Exception {70 when(inputElement.getAttribute("value")).thenReturn("TestUser");71 PageAction action = new PageAction.Builder()72 .browser(seleniumBrowser)73 .action("validate")74 .type(UserFormPage.class.getName())75 .build();76 action.execute(context);77 }78 @Test79 public void testExecutePageValidator() throws Exception {80 PageValidator validator = Mockito.mock(PageValidator.class);81 when(inputElement.getAttribute("value")).thenReturn("TestUser");82 UserFormPage userForm = new UserFormPage();83 PageAction action = new PageAction.Builder()84 .browser(seleniumBrowser)85 .action("validate")86 .page(userForm)87 .validator(validator)88 .build();89 action.execute(context);90 verify(validator).validate(userForm, seleniumBrowser, context);91 }92 @Test93 public void testExecuteAction() throws Exception {94 PageAction action = new PageAction.Builder()95 .browser(seleniumBrowser)96 .action("setUserName")97 .argument("Citrus")98 .page(new UserFormPage())99 .build();100 action.execute(context);101 verify(inputElement).clear();102 verify(inputElement).sendKeys("Citrus");103 }104 @Test105 public void testExecuteActionWithArguments() throws Exception {106 when(webDriver.findElement(By.id("form"))).thenReturn(formElement);107 PageAction action = new PageAction.Builder()108 .browser(seleniumBrowser)109 .action("submit")110 .page(new TestPage())111 .build();112 action.execute(context);113 action = new PageAction.Builder()114 .browser(seleniumBrowser)115 .action("submitWithContext")116 .page(new TestPage())117 .build();118 action.execute(context);119 action = new PageAction.Builder()120 .browser(seleniumBrowser)121 .action("submitWithArgument")122 .argument("ok")123 .page(new TestPage())124 .build();125 action.execute(context);126 action = new PageAction.Builder()127 .browser(seleniumBrowser)128 .action("submitWithArgumentAndContext")129 .argument("ok")130 .page(new TestPage())131 .build();132 action.execute(context);133 verify(formElement, times(4)).submit();134 }135 @Test(expectedExceptions = CitrusRuntimeException.class, expectedExceptionsMessageRegExp = "Unsupported method signature for page action.*")136 public void testExecuteActionNotMatchingArguments() throws Exception {137 when(webDriver.findElement(By.id("form"))).thenReturn(formElement);138 PageAction action = new PageAction.Builder()139 .browser(seleniumBrowser)140 .action("submit")141 .page(new TestPage())142 .argument("Citrus")143 .build();144 action.execute(context);145 verify(inputElement).clear();146 verify(inputElement).sendKeys("Citrus");147 verify(formElement).submit();148 }149 @Test(expectedExceptions = IllegalArgumentException.class)150 public void testExecuteValidationFailed() throws Exception {151 PageAction action = new PageAction.Builder()152 .browser(seleniumBrowser)153 .action("validate")154 .page(new UserFormPage())155 .build();156 action.execute(context);157 }158 @Test(expectedExceptions = CitrusRuntimeException.class, expectedExceptionsMessageRegExp = "Failed to access page type.*")159 public void testInvalidPageType() throws Exception {160 PageAction action = new PageAction.Builder()161 .browser(seleniumBrowser)162 .action("validate")163 .type(UserFormPage.class.getPackage().getName() + ".UnknownPage")164 .build();165 action.execute(context);166 }167 public class TestPage implements WebPage {168 @FindBy(id = "form")169 private WebElement form;170 public void submit() {171 form.submit();172 }173 public void submitWithContext(TestContext context) {174 Assert.assertNotNull(context);...

Full Screen

Full Screen

Source:SeleniumActionBuilder.java Github

copy

Full Screen

...13import com.consol.citrus.selenium.actions.JavaScriptAction;14import com.consol.citrus.selenium.actions.MakeScreenshotAction;15import com.consol.citrus.selenium.actions.NavigateAction;16import com.consol.citrus.selenium.actions.OpenWindowAction;17import com.consol.citrus.selenium.actions.PageAction;18import com.consol.citrus.selenium.actions.SeleniumAction;19import com.consol.citrus.selenium.actions.SetInputAction;20import com.consol.citrus.selenium.actions.StartBrowserAction;21import com.consol.citrus.selenium.actions.StopBrowserAction;22import com.consol.citrus.selenium.actions.StoreFileAction;23import com.consol.citrus.selenium.actions.SwitchWindowAction;24import com.consol.citrus.selenium.actions.WaitUntilAction;25import com.consol.citrus.selenium.endpoint.SeleniumBrowser;26import com.consol.citrus.selenium.model.WebPage;27import com.consol.citrus.util.FileUtils;28import org.springframework.core.io.Resource;29/**30 * @author Christoph Deppisch31 */32public class SeleniumActionBuilder implements TestActionBuilder.DelegatingTestActionBuilder<SeleniumAction> {33 private final com.consol.citrus.selenium.actions.SeleniumActionBuilder delegate = new com.consol.citrus.selenium.actions.SeleniumActionBuilder();34 public SeleniumActionBuilder browser(SeleniumBrowser seleniumBrowser) {35 delegate.browser(seleniumBrowser);36 return this;37 }38 public StartBrowserAction.Builder start() {39 return delegate.start();40 }41 public StartBrowserAction.Builder start(SeleniumBrowser seleniumBrowser) {42 return delegate.start(seleniumBrowser);43 }44 public StopBrowserAction.Builder stop() {45 return delegate.stop();46 }47 public StopBrowserAction.Builder stop(SeleniumBrowser seleniumBrowser) {48 return delegate.stop(seleniumBrowser);49 }50 public AlertAction.Builder alert() {51 return delegate.alert();52 }53 public NavigateAction.Builder navigate(String page) {54 return delegate.navigate(page);55 }56 public PageAction.Builder page(WebPage page) {57 return delegate.page(page);58 }59 public PageAction.Builder page(Class<? extends WebPage> pageType) {60 return delegate.page(pageType);61 }62 public FindElementAction.Builder find() {63 return delegate.find();64 }65 public DropDownSelectAction.Builder select(String option) {66 return delegate.select(option);67 }68 public DropDownSelectAction.Builder select(String ... options) {69 return delegate.select(options);70 }71 public SetInputAction.Builder setInput(String value) {72 return delegate.setInput(value);73 }...

Full Screen

Full Screen

Source:ExtractAction.java Github

copy

Full Screen

...94 }95 public void setElements(Map<By, ExtractDefinition.Element> elements) {96 this.elements = elements;97 }98 public Map<String, String> getPageActions() {99 return pageActions;100 }101 public void setPageActions(Map<String, String> pageActions) {102 this.pageActions = pageActions;103 }104 public String getPageName() {105 return pageName;106 }107 public void setPageName(String name) {108 if (name.contains(".")) {109 this.pageName = name;110 } else if (StringUtils.hasText(webClient.getModelNamespace())) {111 this.pageName = webClient.getModelNamespace() + "." + name;112 } else {113 this.pageName = WebClientConfiguration.PAGE_MODEL_NAMESPACE + "." + name;114 }115 setName(getName() + ":" + name);...

Full Screen

Full Screen

PageAction

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.selenium;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;4import com.consol.citrus.selenium.endpoint.SeleniumBrowser;5import com.consol.citrus.selenium.endpoint.SeleniumHeaders;6import com.consol.citrus.selenium.model.Page;7import com.consol.citrus.selenium.model.PageElement;8import com.consol.citrus.selenium.model.PageElementAction;9import com.consol.citrus.selenium.model.PageElementActionBuilder;10import org.openqa.selenium.By;11import org.openqa.selenium.WebDriver;12import org.openqa.selenium.WebElement;13import org.openqa.selenium.support.FindBy;14import org.testng.annotations.Test;15import java.util.List;16public class PageActionTest extends TestNGCitrusTestRunner {17 public void pageActionTest() {18 selenium().browser()19 selenium().page()20 .actions()21 .click(PageElementActionBuilder.pageElement()22 .id("gbqfbb")23 .build())24 .build()25 .execute(this.createTestContext());26 selenium().page()27 .actions()28 .click(PageElementActionBuilder.pageElement()29 .linkText("Gmail")30 .build())31 .build()32 .execute(this.createTestContext());33 selenium().page()34 .actions()35 .click(PageElementActionBuilder.pageElement()36 .id("identifierNext")37 .build())38 .build()39 .execute(this.createTestContext());40 selenium().page()41 .actions()42 .sendKeys(PageElementActionBuilder.pageElement()43 .id("identifierId")44 .build(), "

Full Screen

Full Screen

PageAction

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.selenium;2import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;3import com.consol.citrus.selenium.endpoint.SeleniumBrowser;4import com.consol.citrus.selenium.endpoint.SeleniumBrowserBuilder;5import org.openqa.selenium.By;6import org.openqa.selenium.WebDriver;7import org.openqa.selenium.chrome.ChromeDriver;8import org.openqa.selenium.chrome.ChromeOptions;9import org.openqa.selenium.remote.DesiredCapabilities;10import org.testng.annotations.Test;11import java.util.HashMap;12import java.util.Map;13public class SeleniumPageActionTest extends TestNGCitrusTestDesigner {14 protected void configure() {15 SeleniumBrowser browser = new SeleniumBrowserBuilder()16 .browserType(SeleniumBrowser.BrowserType.CHROME)17 .build();18 Map<String, String> mobileEmulation = new HashMap<>();19 mobileEmulation.put("deviceName", "iPhone 6/7/8");20 Map<String, Object> chromeOptions = new HashMap<>();21 chromeOptions.put("mobileEmulation", mobileEmulation);22 DesiredCapabilities capabilities = DesiredCapabilities.chrome();23 capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);24 browser.setCapabilities(capabilities);25 variable("browser", browser);26 selenium()27 .browser("${browser}")28 .start();29 selenium()30 .browser("${browser}")31 selenium()32 .browser("${browser}")33 .page()34 .validateTitle("Google");35 selenium()36 .browser("${browser}")37 .element(By.name("q"))38 .type("Citrus");39 selenium()40 .browser("${browser}")41 .element(By.name("btnK"))42 .click();43 selenium()44 .browser("${browser}")45 .page()46 .validateTitle("Citrus - Google Search");47 selenium()48 .browser("${browser}")49 .stop();50 }51}52package com.consol.citrus.selenium;53import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;54import com.consol.citrus.selenium.endpoint.SeleniumBrowser;55import com.consol.citrus.selenium.endpoint.SeleniumBrowserBuilder;56import org.openqa.selenium.By;57import org.openqa.selenium.WebDriver;58import org.openqa.selenium.chrome.ChromeDriver;59import org.openqa.selenium.chrome.ChromeOptions;60import org.openqa.selenium.remote

Full Screen

Full Screen

PageAction

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples.selenium;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;4import org.springframework.core.io.ClassPathResource;5import org.testng.annotations.Test;6public class SeleniumIT extends TestNGCitrusTestRunner {7 public void googleSearch() {8 selenium().pageAction().verifyTitle("Google");9 selenium().pageAction().verifySource(new ClassPathResource("com/consol/citrus/samples/selenium/expected.html"));10 selenium().pageAction().verifyTextPresent("I'm Feeling Lucky");11 selenium().pageAction().verifyTextPresent("Google Search");12 selenium().pageAction().verifyTextPresent("Google offered in: ");13 selenium().pageAction().verifyTextPresent("Advertising Programs Business Solutions About Google Google.com © 2016 - Privacy - Terms");14 selenium().pageAction().verifyTextPresent("Search Settings");15 }16}17package com.consol.citrus.samples.selenium;18import com.consol.citrus.annotations.CitrusTest;19import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;20import org.springframework.core.io.ClassPathResource;21import org.testng.annotations.Test;22public class SeleniumIT extends TestNGCitrusTestRunner {23 public void googleSearch() {24 selenium().pageAction().verifyTitle("Google");25 selenium().pageAction().verifySource(new ClassPathResource("com/consol/citrus/samples/selenium/expected.html"));26 selenium().pageAction().verifyTextPresent("I'm Feeling Lucky");27 selenium().pageAction().verifyTextPresent("Google Search");28 selenium().pageAction().verifyTextPresent("Google offered in: ");29 selenium().pageAction().verifyTextPresent("Advertising Programs Business Solutions About Google Google.com © 2016 - Privacy - Terms");30 selenium().pageAction().verifyTextPresent("Search Settings");

Full Screen

Full Screen

PageAction

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.selenium.actions;2import com.consol.citrus.selenium.endpoint.SeleniumBrowser;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.WebElement;5import org.openqa.selenium.support.ui.ExpectedConditions;6import org.openqa.selenium.support.ui.WebDriverWait;7import org.slf4j.Logger;8import org.slf4j.LoggerFactory;9import org.springframework.util.StringUtils;10import java.util.List;11import java.util.concurrent.TimeUnit;12public class PageAction extends AbstractSeleniumAction {13 private static Logger log = LoggerFactory.getLogger(PageAction.class);14 private String url;15 private String title;16 private String source;17 private String element;18 private String elementLocator;19 private String elementLocatorType;20 private long elementTimeout = 5000;21 private long elementPollingInterval = 500;22 private boolean elementVisibility = true;23 private boolean elementPresence = false;24 public PageAction() {25 super("page");26 }27 protected void execute(SeleniumBrowser browser) {28 WebDriver webDriver = browser.getWebDriver();29 if (StringUtils.hasText(url)) {30 webDriver.get(url);31 }32 if (StringUtils.hasText(title)) {33 if (!webDriver.getTitle().equals(title)) {34 throw new SeleniumActionException("Failed to open web page with title: " + title);35 }36 }37 if (StringUtils.hasText(source)) {38 if (!webDriver.getPageSource().equals(source)) {39 throw new SeleniumActionException("Failed to open web page with source: " + source);40 }41 }42 if (StringUtils.hasText(element)) {43 WebElement webElement = findElement(browser);44 if (elementVisibility && !webElement.isDisplayed()) {45 throw new SeleniumActionException("Failed to open web page with element: " + element);46 }47 if (elementPresence && webElement.isDisplayed()) {48 throw new SeleniumActionException("Failed to open web page with element: " +

Full Screen

Full Screen

PageAction

Using AI Code Generation

copy

Full Screen

1public class 3 extends TestCase {2 public void 3() {3 selenium().start();4 selenium().open("${url}");5 selenium().page().navigateBack();6 selenium()

Full Screen

Full Screen

PageAction

Using AI Code Generation

copy

Full Screen

1public class 3 extends TestNGCitrusTestDesigner {2 public void 3() {3 variable("search", "Citrus");4 selenium().page()5 .open("${url}");6 selenium().page()7 .title("Google");8 selenium().page()9 .source()10 .validate("NOT_NULL");11 selenium().page()12 .source()13 .validate("NOT_NULL", "Page source is not empty");14 selenium().page()15 .source()16 .validate("NOT_NULL", "Page source is not empty", "html");17 selenium().page()18 .source()19 .validate("NOT_NULL", "Page source is not empty", "html", "xpath");20 selenium().page()21 .source()22 .validate("NOT_NULL", "Page source is not empty", "html", "xpath", "xpath");23 selenium().page()24 .source()25 .validate("NOT_NULL", "Page source is not empty", "html", "xpath", "xpath", "xpath");26 selenium().page()27 .source()28 .validate("NOT_NULL", "Page source is not empty", "html", "xpath", "xpath", "xpath", "xpath");29 selenium().page()30 .source()31 .validate("NOT_NULL", "Page source is not empty", "html", "xpath", "xpath", "xpath", "xpath", "xpath");32 selenium().page()33 .source()34 .validate("NOT_NULL", "Page source is not empty", "html", "xpath", "xpath", "xpath", "xpath", "xpath", "xpath");35 selenium().page()36 .source()37 .validate("NOT_NULL", "Page source is not empty", "html", "

Full Screen

Full Screen

PageAction

Using AI Code Generation

copy

Full Screen

1public class 3 extends CitrusTestDesigner {2 public void 3() {3 }4}5public class 4 extends CitrusTestDesigner {6 public void 4() {7 }8}9public class 5 extends CitrusTestDesigner {10 public void 5() {11 }12}13public class 6 extends CitrusTestDesigner {14 public void 6() {15 }16}17public class 7 extends CitrusTestDesigner {18 public void 7() {19 }20}

Full Screen

Full Screen

PageAction

Using AI Code Generation

copy

Full Screen

1public class 3 extends TestAction {2 public void doExecute(TestContext context) {3 new PageAction.Builder()4 .browser("chrome")5 .build()6 .execute(context);7 }8}9public class 4 extends TestAction {10 public void doExecute(TestContext context) {11 new PageAction.Builder()12 .browser("chrome")13 .build()14 .execute(context);15 }16}17public class 5 extends TestAction {18 public void doExecute(TestContext context) {19 new PageAction.Builder()20 .browser("chrome")21 .build()22 .execute(context);23 }24}25public class 6 extends TestAction {26 public void doExecute(TestContext context) {27 new PageAction.Builder()28 .browser("chrome")29 .build()30 .execute(context);31 }32}33public class 7 extends TestAction {34 public void doExecute(TestContext context) {35 new PageAction.Builder()36 .browser("chrome")37 .build()38 .execute(context);39 }40}41public class 8 extends TestAction {42 public void doExecute(TestContext context) {43 new PageAction.Builder()44 .browser("chrome")45 .build()46 .execute(context);47 }48}

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