Best Balin code snippet using com.github.epadronu.balin.exceptions.MissingPageUrlException
Browser.kt
Source:Browser.kt
...19/* ***************************************************************************/20import com.github.epadronu.balin.config.Configuration21import com.github.epadronu.balin.config.ConfigurationBuilder22import com.github.epadronu.balin.config.ConfigurationSetup23import com.github.epadronu.balin.exceptions.MissingPageUrlException24import com.github.epadronu.balin.exceptions.PageImplicitAtVerificationException25import com.github.epadronu.balin.utils.ThreadLocalDelegate26import org.openqa.selenium.Alert27import org.openqa.selenium.NoSuchWindowException28import org.openqa.selenium.WebDriver29import org.openqa.selenium.WebElement30import org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent31import kotlin.reflect.full.primaryConstructor32/* ***************************************************************************/33/* ***************************************************************************/34/**35 * Balin's backbone. The `Browser` interface binds together the different36 * abstractions that form part of the library.37 *38 * Additionally, this interface defines the entry point for the Domain-Specific39 * Language which Balin is built around.40 */41interface Browser : JavaScriptSupport, WaitingSupport, WebDriver {42 companion object {43 /**44 * The builder in charge of generating the configuration.45 */46 private val configurationBuilder: ConfigurationBuilder by ThreadLocalDelegate {47 ConfigurationBuilder()48 }49 /**50 * The name of the property that dictates which setup to use.51 */52 internal const val BALIN_SETUP_NAME_PROPERTY: String = "balin.setup.name"53 /**54 * Retrieves the configuration generated by the builder, taking in55 * account the value of the [BALIN_SETUP_NAME_PROPERTY] property.56 */57 internal val desiredConfiguration: ConfigurationSetup58 get() = configurationBuilder.build().run {59 setups[System.getProperty(BALIN_SETUP_NAME_PROPERTY) ?: "default"] ?: this60 }61 /**62 * Domain-Specific language that let's you configure Balin's global63 * behavior.64 *65 * @sample com.github.epadronu.balin.config.ConfigurationTests.call_the_configure_method_and_make_changes66 *67 * @param block here you can interact with the DSL.68 */69 fun configure(block: ConfigurationBuilder.() -> Unit) {70 block(configurationBuilder)71 }72 /**73 * This method represents the entry point for the Domain-Specific74 * Language which Balin is built around.75 *76 * `drive` is the main abstraction layer for Selenium-WebDriver. Inside77 * the [block] it receives as parameter, you can interact with the78 * driver and use all the features Balin has to offer.79 *80 * @sample com.github.epadronu.balin.core.BrowserTests.perform_a_simple_web_navigation81 *82 * @param driverFactory provides the driver on which the navigation and interactions will be performed.83 * @param autoQuit indicates if the driver should quit at the end of the [block].84 * @param block here you interact with the driver alongside of Balin's assistance.85 */86 fun drive(87 driverFactory: () -> WebDriver = desiredConfiguration.driverFactory,88 autoQuit: Boolean = desiredConfiguration.autoQuit,89 block: Browser.() -> Unit) = drive(Configuration(autoQuit, driverFactory), block)90 /**91 * This method represents the entry point for the Domain-Specific92 * Language which Balin is built around.93 *94 * `drive` is the main abstraction layer for Selenium-WebDriver. Inside95 * the [block] it receives as parameter, you can interact with the96 * driver and use all the features Balin has to offer.97 *98 * @sample com.github.epadronu.balin.core.BrowserTests.perform_a_simple_web_navigation99 *100 * @param configuration defines Balin's local behavior for [block] only.101 * @param block here you interact with the driver alongside of Balin's assistance.102 */103 fun drive(configuration: Configuration, block: Browser.() -> Unit) {104 val desiredConfiguration = configuration.run {105 setups[System.getProperty(BALIN_SETUP_NAME_PROPERTY) ?: "default"] ?: this106 }107 BrowserImpl(desiredConfiguration).apply {108 try {109 block()110 } catch (throwable: Throwable) {111 throw throwable112 } finally {113 if (configurationSetup.autoQuit) {114 quit()115 }116 }117 }118 }119 }120 /**121 * Tells the browser at what page it should be located.122 *123 * If the page defines an _implicit at verification_, then it will be124 * invoked immediately. If such verification fails, Balin will throw a125 * [PageImplicitAtVerificationException] in order to perform an early126 * failure.127 *128 * @sample com.github.epadronu.balin.core.BrowserTests.model_a_page_into_a_Page_Object_and_interact_with_it_via_the_at_method129 *130 * @param T the page's type.131 * @param factory provides an instance of the page given the driver being used by the browser.132 * @Returns An instance of the current page.133 * @throws PageImplicitAtVerificationException if the page has an _implicit at verification_ which have failed.134 */135 fun <T : Page> at(factory: (Browser) -> T): T = factory(this).apply {136 if (!verifyAt()) {137 throw PageImplicitAtVerificationException()138 }139 }140 /**141 * Navigates to the given page.142 *143 * If the page has not defined a URL, then a144 * [MissingPageUrlException] will be thrown immediately since145 * is not possible to perform the navigation.146 *147 * If the page defines an _implicit at verification_, then it148 * will be invoked immediately. If such verification fails, Balin149 * will throw a [PageImplicitAtVerificationException] in order to150 * perform an early failure.151 *152 * @sample com.github.epadronu.balin.core.BrowserTests.perform_a_simple_web_navigation153 *154 * @param T the page's type.155 * @param factory provides an instance of the page given the driver being used by the browser.156 * @Returns An instance of the current page.157 * @throws MissingPageUrlException if the page has not defined a URL.158 * @throws PageImplicitAtVerificationException if the page has an _implicit at verification_ which have failed.159 * @see org.openqa.selenium.WebDriver.get160 */161 fun <T : Page> to(factory: (Browser) -> T): T = factory(this).apply {162 get(url ?: throw MissingPageUrlException())163 if (!verifyAt()) {164 throw PageImplicitAtVerificationException()165 }166 }167 /**168 * Navigates to the given URL.169 *170 * @param url the URL the browser will navigate to.171 * @return The browser's current URL.172 *173 * @see org.openqa.selenium.WebDriver.get174 */175 fun to(url: String): String {176 get(url)...
PageTests.kt
Source:PageTests.kt
...16/* ***************************************************************************/17package com.github.epadronu.balin.core18/* ***************************************************************************/19/* ***************************************************************************/20import com.github.epadronu.balin.exceptions.MissingPageUrlException21import com.github.epadronu.balin.exceptions.PageImplicitAtVerificationException22import com.github.epadronu.balin.extensions.`$`23import org.openqa.selenium.WebDriver24import org.openqa.selenium.htmlunit.HtmlUnitDriver25import org.testng.Assert.assertEquals26import org.testng.Assert.expectThrows27import org.testng.Assert.fail28import org.testng.annotations.DataProvider29import org.testng.annotations.Test30import com.gargoylesoftware.htmlunit.BrowserVersion.FIREFOX_60 as BROWSER_VERSION31/* ***************************************************************************/32/* ***************************************************************************/33class PageTests {34 @DataProvider(name = "JavaScript-incapable WebDriver factory", parallel = true)35 fun `Create a JavaScript-incapable WebDriver factory`() = arrayOf(36 arrayOf({ HtmlUnitDriver(BROWSER_VERSION) })37 )38 @Test(dataProvider = "JavaScript-incapable WebDriver factory")39 fun `Model a page into a Page Object and navigate to it`(driverFactory: () -> WebDriver) {40 // Given the Kotlin's website index page41 class IndexPage(browser: Browser) : Page(browser) {42 override val url = "https://kotlinlang.org/"43 }44 Browser.drive(driverFactory) {45 // When I visit such page46 val url = to(::IndexPage).url47 // Then I should change the browser's URL to the one of the given page48 assertEquals(currentUrl, url)49 // And I should get the title of the Kotlin's website index page50 assertEquals(title, "Kotlin Programming Language")51 }52 }53 @Test(description = "Model a page into a Page Object with no URL and try to navigate to it",54 dataProvider = "JavaScript-incapable WebDriver factory")55 fun model_a_page_into_a_page_object_with_no_url_and_try_to_navigate_to_it(driverFactory: () -> WebDriver) {56 // Given a page with no URL57 class TestPage(browser: Browser) : Page(browser)58 // When I visit such page59 Browser.drive(driverFactory) {60 // Then MissingPageUrlException should be throw61 expectThrows(MissingPageUrlException::class.java) {62 to(::TestPage)63 }64 }65 }66 @Test(dataProvider = "JavaScript-incapable WebDriver factory")67 fun `Model a page into a Page Object with a valid at clause`(driverFactory: () -> WebDriver) {68 // Given the Kotlin's website index page with a valid `at` clause69 class IndexPage(browser: Browser) : Page(browser) {70 override val url = "https://kotlinlang.org/"71 override val at = at {72 title == "Kotlin Programming Language"73 }74 }75 try {...
MissingPageUrlException.kt
Source:MissingPageUrlException.kt
...23 * are used with a page that has not defined a url.24 *25 * @sample com.github.epadronu.balin.core.PageTests.model_a_page_into_a_page_object_with_no_url_and_try_to_navigate_to_it26 */27class MissingPageUrlException : BalinException("The page doesn't have a URL for the browser to navigate to")28/* ***************************************************************************/...
MissingPageUrlException
Using AI Code Generation
1MissingPageUrlException exception = new MissingPageUrlException ();2System . out . println ( exception . getMessage ());3MissingPageTitleException exception = new MissingPageTitleException ();4System . out . println ( exception . getMessage ());5MissingPageElementTextException exception = new MissingPageElementTextException ();6System . out . println ( exception . getMessage ());7MissingPageElementAttributeException exception = new MissingPageElementAttributeException ();8System . out . println ( exception . getMessage ());9MissingPageElementCssValueException exception = new MissingPageElementCssValueException ();10System . out . println ( exception . getMessage ());11MissingPageElementLocationException exception = new MissingPageElementLocationException ();12System . out . println ( exception . getMessage ());13MissingPageElementSizeException exception = new MissingPageElementSizeException ();14System . out . println ( exception . getMessage ());15MissingPageElementTagException exception = new MissingPageElementTagException ();16System . out . println ( exception . getMessage ());17MissingPageElementValueException exception = new MissingPageElementValueException ();18System . out . println ( exception . getMessage ());19MissingPageElementSelectedException exception = new MissingPageElementSelectedException ();20System . out . println ( exception . getMessage ());21MissingPageElementEnabledException exception = new MissingPageElementEnabledException ();22System . out . println ( exception . getMessage ());
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!