How to use drive method of com.github.epadronu.balin.core.Browser class

Best Balin code snippet using com.github.epadronu.balin.core.Browser.drive

Browser.kt

Source:Browser.kt Github

copy

Full Screen

...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)177 return currentUrl178 }179}180/* ***************************************************************************/181/* ***************************************************************************/182/**183 * Switches to the currently active modal dialog for this particular driver instance.184 *185 * You can interact with the dialog handler only inside [alertContext].186 *187 * @sample com.github.epadronu.balin.core.WithAlertTests.validate_context_switching_to_and_from_an_alert_popup_and_accept_it188 *189 * @param alertContext here you can interact with the dialog handler.190 * @throws org.openqa.selenium.NoAlertPresentException If the dialog cannot be found.191 */192inline fun Browser.withAlert(alertContext: Alert.() -> Unit): Unit = try {193 switchTo().alert().run {194 alertContext()195 if (this == alertIsPresent().apply(driver)) {196 dismiss()197 }198 }199} catch (throwable: Throwable) {200 throw throwable201} finally {202 switchTo().defaultContent()203}204/**205 * Select a frame by its (zero-based) index and switch the driver's context to206 * it.207 *208 * Once the frame has been selected, all subsequent calls on the WebDriver209 * interface are made to that frame till the end of [iFrameContext].210 *211 * If a exception is thrown inside [iFrameContext], the driver will return to212 * its default context.213 *214 * @sample com.github.epadronu.balin.core.WithFrameTests.validate_context_switching_to_and_from_an_iframe_with_index215 *216 * @param index (zero-based) index.217 * @param iFrameContext here you can interact with the given IFrame.218 * @throws org.openqa.selenium.NoSuchFrameException If the frame cannot be found.219 */220inline fun Browser.withFrame(index: Int, iFrameContext: () -> Unit): Unit = try {221 switchTo().frame(index)222 iFrameContext()223} catch (throwable: Throwable) {224 throw throwable225} finally {226 switchTo().defaultContent()227}228/**229 * Select a frame by its name or ID. Frames located by matching name attributes230 * are always given precedence over those matched by ID.231 *232 * Once the frame has been selected, all subsequent calls on the WebDriver233 * interface are made to that frame till the end of [iFrameContext].234 *235 * If a exception is thrown inside [iFrameContext], the driver will return to236 * its default context.237 *238 * @sample com.github.epadronu.balin.core.WithFrameTests.validate_context_switching_to_and_from_an_iframe_with_id239 *240 * @param nameOrId the name of the frame window, the id of the &lt;frame&gt; or &lt;iframe&gt; element, or the (zero-based) index.241 * @param iFrameContext here you can interact with the given IFrame.242 * @throws org.openqa.selenium.NoSuchFrameException If the frame cannot be found.243 */244inline fun Browser.withFrame(nameOrId: String, iFrameContext: () -> Unit): Unit = try {245 switchTo().frame(nameOrId)246 iFrameContext()247} catch (throwable: Throwable) {248 throw throwable249} finally {250 switchTo().defaultContent()251}252/**253 * Select a frame using its previously located WebElement.254 *255 * Once the frame has been selected, all subsequent calls on the WebDriver256 * interface are made to that frame till the end of [iFrameContext].257 *258 * If a exception is thrown inside [iFrameContext], the driver will return to259 * its default context.260 *261 * @sample com.github.epadronu.balin.core.WithFrameTests.validate_context_switching_to_and_from_an_iframe_with_web_element262 *263 * @param webElement the frame element to switch to.264 * @param iFrameContext here you can interact with the given IFrame.265 * @throws org.openqa.selenium.NoSuchFrameException If the frame cannot be found.266 */267inline fun Browser.withFrame(webElement: WebElement, iFrameContext: () -> Unit): Unit = try {268 switchTo().frame(webElement)269 iFrameContext()270} catch (throwable: Throwable) {271 throw throwable272} finally {273 switchTo().defaultContent()274}275/**276 * Select a frame by its (zero-based) index and switch the driver's context to277 * it.278 *279 * Once the frame has been selected, all subsequent calls on the WebDriver280 * interface are made to that frame via a `Page Object` of type [T] till281 * the end of [iFrameContext].282 *283 * If a exception is thrown inside [iFrameContext], the driver will return to284 * its default context.285 *286 * @sample com.github.epadronu.balin.core.WithFrameTests.validate_context_switching_to_and_from_an_iframe_with_index_and_pages287 *288 * @param T the `Page Object`'s type.289 * @param index (zero-based) index.290 * @param iFrameContext here you can interact with the given IFrame via a `Page Object`.291 * @throws org.openqa.selenium.NoSuchFrameException If the frame cannot be found.292 */293inline fun <reified T : Page> Browser.withFrame(index: Int, iFrameContext: T.() -> Unit): Unit = try {294 switchTo().frame(index)295 @Suppress("UNCHECKED_CAST")296 iFrameContext(at(T::class.primaryConstructor as (Browser) -> T))297} catch (throwable: Throwable) {298 throw throwable299} finally {300 switchTo().defaultContent()301}302/**303 * Select a frame by its name or ID. Frames located by matching name attributes304 * are always given precedence over those matched by ID.305 *306 * Once the frame has been selected, all subsequent calls on the WebDriver307 * interface are made to that frame via a `Page Object` of type [T] till308 * the end of [iFrameContext].309 *310 * If a exception is thrown inside [iFrameContext], the driver will return to311 * its default context.312 *313 * @sample com.github.epadronu.balin.core.WithFrameTests.validate_context_switching_to_and_from_an_iframe_with_id_and_pages314 *315 * @param T the `Page Object`'s type.316 * @param nameOrId the name of the frame window, the id of the &lt;frame&gt; or &lt;iframe&gt; element, or the (zero-based) index.317 * @param iFrameContext here you can interact with the given IFrame via a `Page Object`.318 * @throws org.openqa.selenium.NoSuchFrameException If the frame cannot be found.319 */320inline fun <reified T : Page> Browser.withFrame(nameOrId: String, iFrameContext: T.() -> Unit): Unit = try {321 switchTo().frame(nameOrId)322 @Suppress("UNCHECKED_CAST")323 iFrameContext(at(T::class.primaryConstructor as (Browser) -> T))324} catch (throwable: Throwable) {325 throw throwable326} finally {327 switchTo().defaultContent()328}329/**330 * Select a frame using its previously located WebElement.331 *332 * Once the frame has been selected, all subsequent calls on the WebDriver333 * interface are made to that frame via a `Page Object` of type [T] till334 * the end of [iFrameContext].335 *336 * If a exception is thrown inside [iFrameContext], the driver will return to337 * its default context.338 *339 * @sample com.github.epadronu.balin.core.WithFrameTests.validate_context_switching_to_and_from_an_iframe_with_web_element_and_pages340 *341 * @param T the `Page Object`'s type.342 * @param webElement the frame element to switch to.343 * @param iFrameContext here you can interact with the given IFrame via a `Page Object`.344 * @throws org.openqa.selenium.NoSuchFrameException If the frame cannot be found.345 */346inline fun <reified T : Page> Browser.withFrame(webElement: WebElement, iFrameContext: T.() -> Unit): Unit = try {347 switchTo().frame(webElement)348 @Suppress("UNCHECKED_CAST")349 iFrameContext(at(T::class.primaryConstructor as (Browser) -> T))350} catch (throwable: Throwable) {351 throw throwable352} finally {353 switchTo().defaultContent()354}355/**356 * Switch the focus of future commands for this driver to the window with the357 * given name/handle.358 *359 * The name/handle can be omitted and the switching will be performed360 * automatically if and only if there is only two windows currently361 * opened.362 *363 * Once the window has been selected, all subsequent calls on the WebDriver364 * interface are made to that window till the end of [windowContext].365 *366 * If a exception is thrown inside [windowContext], the driver will return to367 * the previous window.368 *369 * @sample com.github.epadronu.balin.core.WithWindowTests.validate_context_switching_to_and_from_a_window370 *371 * @param nameOrHandle The name of the window or the handle as returned by [WebDriver.getWindowHandle]372 * @param windowContext Here you can interact with the given window.373 * @throws NoSuchWindowException If the window cannot be found or, in the case of no name or handle is indicated,374 * there is not exactly two windows currently opened.375 */376inline fun Browser.withWindow(nameOrHandle: String? = null, windowContext: WebDriver.() -> Unit) {377 val originalWindow = windowHandle378 val targetWindow = nameOrHandle ?: windowHandles.toSet().minus(originalWindow).run {379 when (size) {380 0 -> throw NoSuchWindowException("No new window was found")...

Full Screen

Full Screen

HelloWorld.kt

Source:HelloWorld.kt Github

copy

Full Screen

...61/* ***************************************************************************/62/* ***************************************************************************/63class HelloWorldTest {64 @BeforeClass65 fun `configure the driver`() {66 /* You may need to provide the path for Firefox as well as for the gecko-driver67 * is you wish to run the test68 */69 }70 @Test71 fun `Test the HelloWorld example`() {72 Browser.drive {73 val indexPage = to(::IndexPage)74 val tryItPage = indexPage.goToTryItPage()75 Assert.assertEquals(tryItPage.runHelloWorld(), "Hello, world!!!")76 }77 }78}79/* ***************************************************************************/...

Full Screen

Full Screen

ConfigurationSetup.kt

Source:ConfigurationSetup.kt Github

copy

Full Screen

...30 * to customize Balin's behavior.31 */32interface ConfigurationSetup {33 /**34 * Control whether the driver quits at the end35 * of [com.github.epadronu.balin.core.Browser.drive].36 *37 * autoQuit = false38 */39 val autoQuit: Boolean40 /**41 * The factory that will create the driver to be used when invoking42 * [com.github.epadronu.balin.core.Browser.drive].43 *44 * driverFactory = ::FirefoxDriver45 */46 val driverFactory: () -> WebDriver47 /**48 * Control the amount of time between attempts when using49 * [com.github.epadronu.balin.core.WaitingSupport.waitFor].50 *51 * waitForSleepTimeInMilliseconds = 1_000L // One second52 */53 val waitForSleepTimeInMilliseconds: Long54 /**55 * Control the total amount of time to wait for a condition evaluated by56 * [com.github.epadronu.balin.core.WaitingSupport.waitFor] to hold.57 *58 * waitForTimeOutTimeInSecond = 10L // Ten seconds59 */60 val waitForTimeOutTimeInSeconds: Long...

Full Screen

Full Screen

ConfigurationSetupBuilder.kt

Source:ConfigurationSetupBuilder.kt Github

copy

Full Screen

...26 *27 * @see ConfigurationSetup28 * @sample com.github.epadronu.balin.config.ConfigurationTests.call_the_configure_method_and_make_changes29 *30 * @property autoQuit control whether the driver quits at the end of [com.github.epadronu.balin.core.Browser.drive].31 * @property driverFactory the factory that will create the driver to be used when invoking [com.github.epadronu.balin.core.Browser.drive].32 * @property waitForSleepTimeInMilliseconds control the amount of time between attempts when using [com.github.epadronu.balin.core.WaitingSupport.waitFor].33 * @property waitForTimeOutTimeInSeconds control the total amount of time to wait for a condition evaluated by [com.github.epadronu.balin.core.WaitingSupport.waitFor] to hold.34 * @constructor Creates a new configuration setup builder.35 */36open class ConfigurationSetupBuilder {37 var autoQuit: Boolean = ConfigurationSetup.Default.autoQuit38 var driverFactory: () -> WebDriver = ConfigurationSetup.Default.driverFactory39 var waitForSleepTimeInMilliseconds: Long = ConfigurationSetup.Default.waitForSleepTimeInMilliseconds40 var waitForTimeOutTimeInSeconds: Long = ConfigurationSetup.Default.waitForTimeOutTimeInSeconds41 /**42 * Creates a new configuration setup.43 *44 * @return a new configuration setup using the options provided to the builder.45 */46 open fun build(): ConfigurationSetup = Configuration(47 autoQuit, driverFactory, waitForSleepTimeInMilliseconds, waitForTimeOutTimeInSeconds)48}49/* ***************************************************************************/...

Full Screen

Full Screen

Configuration.kt

Source:Configuration.kt Github

copy

Full Screen

...25 * other configuration setups, to be used according to the `balin.setup.name`26 * system property.27 *28 * @see ConfigurationSetup29 * @sample com.github.epadronu.balin.config.ConfigurationTests.call_the_drive_method_with_a_development_setup_configuration_and_use_it30 *31 * @property autoQuit control whether the driver quits at the end of [com.github.epadronu.balin.core.Browser.drive].32 * @property driverFactory the factory that will create the driver to be used when invoking [com.github.epadronu.balin.core.Browser.drive].33 * @property waitForSleepTimeInMilliseconds control the amount of time between attempts when using [com.github.epadronu.balin.core.WaitingSupport.waitFor].34 * @property waitForTimeOutTimeInSeconds control the total amount of time to wait for a condition evaluated by [com.github.epadronu.balin.core.WaitingSupport.waitFor] to hold.35 * @property setups may contain configuration setups to be used according to the `balin.setup.name` system property.36 * @constructor Creates a new configuration setup37 */38data class Configuration(39 override val autoQuit: Boolean = ConfigurationSetup.Default.autoQuit,40 override val driverFactory: () -> WebDriver = ConfigurationSetup.Default.driverFactory,41 override val waitForSleepTimeInMilliseconds: Long = ConfigurationSetup.Default.waitForSleepTimeInMilliseconds,42 override val waitForTimeOutTimeInSeconds: Long = ConfigurationSetup.Default.waitForTimeOutTimeInSeconds,43 val setups: Map<String, ConfigurationSetup> = emptyMap()) : ConfigurationSetup44/* ***************************************************************************/...

Full Screen

Full Screen

ConfigurationBuilder.kt

Source:ConfigurationBuilder.kt Github

copy

Full Screen

...31 var setups: Map<String, ConfigurationSetup> = mapOf()32 /**33 * Domain-Specific language that let's you create a configuration.34 *35 * @sample com.github.epadronu.balin.config.ConfigurationTests.call_the_drive_method_with_a_development_setup_configuration_and_use_it36 *37 * @param block here you can interact with the DSL.38 */39 fun setup(block: ConfigurationSetupBuilder.() -> Unit): ConfigurationSetup = ConfigurationSetupBuilder().apply {40 block()41 }.build()42 /**43 * Creates a new configuration.44 *45 * @return a new configuration setup using the options provided to the builder.46 */47 override fun build(): Configuration = Configuration(48 autoQuit, driverFactory, waitForSleepTimeInMilliseconds, waitForTimeOutTimeInSeconds, setups)49}50/* ***************************************************************************/...

Full Screen

Full Screen

ScreenshotsTest.kt

Source:ScreenshotsTest.kt Github

copy

Full Screen

...26@Listeners(TestListener::class)27class ScreenshotsTest : BaseTest() {28 @Test29 fun `Navigate to DuckDuckGo's index page`() {30 Browser.drive({ webDriver }, autoQuit = false) {31 get("https://www.duckduckgo.com")32 Assert.assertEquals(title, "DuckDuckGo — Privacy, simplified.")33 }34 }35 @Test36 fun `Navigate to Searx's index page`() {37 Browser.drive({ webDriver }, autoQuit = false) {38 get("https://www.searx.me")39 Assert.assertEquals(title, "searx.me")40 }41 }42}43/* ***************************************************************************/

Full Screen

Full Screen

StepDefinition.kt

Source:StepDefinition.kt Github

copy

Full Screen

...26/* ***************************************************************************/27open class StepDefinition {28 companion object {29 @JvmStatic30 var driver by ThreadLocalDelegate<WebDriver>()31 }32 fun drive(block: Browser.() -> Unit): ByteArray {33 Browser.drive(autoQuit = false, driverFactory = { driver }) {34 block()35 }36 return takeScreenshots()37 }38 fun takeScreenshots(): ByteArray = (driver as TakesScreenshot).getScreenshotAs(OutputType.BYTES)39}40/* ***************************************************************************/...

Full Screen

Full Screen

drive

Using AI Code Generation

copy

Full Screen

1import com.github.epadronu.balin.core.Browser;2import com.github.epadronu.balin.core.BrowserFactory;3import com.github.epadronu.balin.core.BrowserFactory.BrowserType;4public class Demo {5 public static void main(String[] args) {6 Browser browser = BrowserFactory.getBrowser(BrowserType.CHROME);7 }8}9import com.github.epadronu.balin.core.Browser;10import com.github.epadronu.balin.core.BrowserFactory;11import com.github.epadronu.balin.core.BrowserFactory.BrowserType;12public class Demo {13 public static void main(String[] args) {14 Browser browser = BrowserFactory.getBrowser(BrowserType.FIREFOX);15 }16}17import com.github.epadronu.balin.core.Browser;18import com.github.epadronu.balin.core.BrowserFactory;19import com.github.epadronu.balin.core.BrowserFactory.BrowserType;20public class Demo {21 public static void main(String[] args) {22 Browser browser = BrowserFactory.getBrowser(BrowserType.INTERNET_EXPLORER);23 }24}25import com.github.epadronu.balin.core.Browser;26import com.github.epadronu.balin.core.BrowserFactory;27import com.github.epadronu.balin.core.BrowserFactory.BrowserType;28public class Demo {29 public static void main(String[] args) {30 Browser browser = BrowserFactory.getBrowser(BrowserType.HTML_UNIT);31 }32}33import com.github.epadronu.balin.core.Browser;34import com.github.epadronu.balin.core.BrowserFactory;35import com.github.epadronu.balin.core.BrowserFactory.BrowserType;36public class Demo {37 public static void main(String[] args) {38 Browser browser = BrowserFactory.getBrowser(BrowserType.HTML_UNIT_WITH

Full Screen

Full Screen

drive

Using AI Code Generation

copy

Full Screen

1 Browser.drive(driver, new Balin() {2 public void drive() {3 driver.manage().window().maximize();4 }5 });6 Balin balin = new Balin(driver);7 balin.waitForPageToLoad();8 balin.waitForElementToLoad("q");9 balin.waitForElementToLoad(By.name("q"));10 balin.waitForElementToLoad(By.name("q"), 10);11 balin.waitForElementToLoad(By.name("q"), 10, 1000);12 balin.waitForElementToLoad(By.name("q"), 10, 1000, 500);13 balin.waitForElementToLoad(By.name("q"), 10, 1000, 500, "Element not found");14 balin.waitForElementToLoad(By.name("q"), 10, 1000, 500, "Element not found", new Exception());15 balin.waitForElementToLoad(By.name("q"), 10, 1000, 500, "Element not found", new Exception(), new RuntimeException());16 balin.waitForElementToLoad(By

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 Balin 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