How to use ClickAndNavigateSupport class of com.github.epadronu.balin.core package

Best Balin code snippet using com.github.epadronu.balin.core.ClickAndNavigateSupport

Run Balin automation tests on LambdaTest cloud grid

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

Page.kt

Source: Page.kt Github

copy
1/******************************************************************************
2 * Copyright 2016 Edinson E. Padrón Urdaneta
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
17/* ***************************************************************************/
18package com.github.epadronu.balin.core
19/* ***************************************************************************/
20
21/* ***************************************************************************/
22import org.openqa.selenium.SearchContext
23import org.openqa.selenium.WebElement
24/* ***************************************************************************/
25
26/* ***************************************************************************/
27/**
28 * This class is the corner stone for Balin's implementation of the
29 * _Page Object Design Pattern_. All classes that model a Web page/view most
30 * extend this one.
31 *
32 * @sample com.github.epadronu.balin.core.PageTests.model_a_page_into_a_page_object_navigate_and_interact_with
33 *
34 * @param browser the browser used by the page in order to interact with the underlying web content.
35 * @constructor Create a new instance with the given browser as its bridge with the web content the page care about.
36 */
37abstract class Page(val browser: Browser) : ClickAndNavigateSupport,
38    ComponentMappingSupport,
39    JavaScriptSupport by browser,
40    SearchContext by browser,
41    WaitingSupport by browser {
42
43    companion object {
44        /**
45         * This method eases the definition of a page's _implicit at verification_.
46         *
47         * @sample com.github.epadronu.balin.core.PageTests.model_a_page_into_a_page_object_navigate_and_interact_with
48         *
49         * @param block context within which you can interact with the browser.
50         * @return The [block] unchanged.
51         */
52        @JvmStatic
53        fun at(block: Browser.() -> Any): Browser.() -> Any = block
54    }
55
56    /**
57     * Defines an optional _implicit verification_ to be checked as soon as the
58     * browser navigates to the page.
59     *
60     * Useful for performing early failure.
61     *
62     * @sample com.github.epadronu.balin.core.PageTests.model_a_page_into_a_page_object_navigate_and_interact_with
63     */
64    open val at: Browser.() -> Any = { true }
65
66    /**
67     * Defines an optional URL, which will be used when invoking
68     * [Browser.to] with a page factory.
69     *
70     * @sample com.github.epadronu.balin.core.PageTests.model_a_page_into_a_page_object_navigate_and_interact_with
71     */
72    open val url: String? = null
73
74    /**
75     * Click on an element and tells the browser it will navigate to the given
76     * page as consequence of such action.
77     *
78     * @sample com.github.epadronu.balin.core.PageTests.use_WebElement_click_in_a_page_to_place_the_browser_at_a_different_page
79     *
80     * @receiver the [WebElement][org.openqa.selenium.WebElement] to be clicked on.
81     * @param factory provides an instance of the page given the driver being used by the browser.
82     * @Returns An instance of the page the browser will navigate to.
83     * @throws PageImplicitAtVerificationException if the page has an _implicit at verification_ which have failed.
84     */
85    override fun <T : Page> WebElement.click(factory: (Browser) -> T): T {
86        this.click()
87
88        return browser.at(factory)
89    }
90
91    override fun <T : Component> WebElement.component(factory: (Page, WebElement) -> T): T = factory(this@Page, this)
92
93    override fun <T : Component> List<WebElement>.component(factory: (Page, WebElement) -> T): List<T> = this.map {
94        factory(this@Page, it)
95    }
96
97    /**
98     * Evaluate the page's _implicit at verification_.
99     *
100     * @return true if the verification passed, false otherwise.
101     */
102    internal fun verifyAt(): Boolean = when (val result = at(browser)) {
103        is Boolean -> result
104        is Unit -> true
105        else -> throw Error("Expressions of type `${result.javaClass.canonicalName}` are not allowed.")
106    }
107}
108/* ***************************************************************************/
109
Full Screen

Component.kt

Source: Component.kt Github

copy
1/******************************************************************************
2 * Copyright 2016 Edinson E. Padrón Urdaneta
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
17/* ***************************************************************************/
18package com.github.epadronu.balin.core
19/* ***************************************************************************/
20
21/* ***************************************************************************/
22import org.openqa.selenium.SearchContext
23import org.openqa.selenium.WebElement
24/* ***************************************************************************/
25
26/* ***************************************************************************/
27/**
28 * A component is a reusable piece of functionality that can be shared among
29 * several pages, and which interaction can be performed independently of other
30 * pieces in the web page.
31 *
32 * @sample com.github.epadronu.balin.core.ComponentTests.model_pieces_of_the_page_as_single_and_nested_components
33 *
34 * @param page the page the component is linked to.
35 * @param rootElement the component's root element.
36 * @constructor Create a new component, given the page it's linked to and its root element.
37 */
38abstract class Component(val page: Page, val rootElement: WebElement) : ClickAndNavigateSupport by page,
39    ComponentMappingSupport by page,
40    JavaScriptSupport by page,
41    SearchContext by rootElement,
42    WaitingSupport by page {
43
44    /**
45     * The browser used by the component in order to interact with the
46     * underlying web content.
47     */
48    val browser: Browser = page.browser
49}
50/* ***************************************************************************/
51
Full Screen

ClickAndNavigateSupport.kt

Source: ClickAndNavigateSupport.kt Github

copy
1/******************************************************************************
2 * Copyright 2016 Edinson E. Padrón Urdaneta
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
17/* ***************************************************************************/
18package com.github.epadronu.balin.core
19/* ***************************************************************************/
20
21/* ***************************************************************************/
22import org.openqa.selenium.WebElement
23/* ***************************************************************************/
24
25/* ***************************************************************************/
26/**
27 * This interface defines a method to click on an element and tell the browser
28 * it will navigate to a different page as consequence of such action.
29 */
30interface ClickAndNavigateSupport {
31
32    /**
33     * Click on an element and tells the browser it will navigate to the given
34     * page as consequence of such action.
35     *
36     * @sample com.github.epadronu.balin.core.PageTests.use_WebElement_click_in_a_page_to_place_the_browser_at_a_different_page
37     *
38     * @receiver the [WebElement][org.openqa.selenium.WebElement] to be clicked on.
39     * @param factory provides an instance of the page given the driver being used by the browser.
40     * @Returns An instance of the page the browser will navigate to.
41     * @throws PageImplicitAtVerificationException if the page has an _implicit at verification_ which have failed.
42     */
43    fun <T : Page> WebElement.click(factory: (Browser) -> T): T
44}
45/* ***************************************************************************/
46
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used methods in ClickAndNavigateSupport

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie