How to use BaseTest class of com.github.epadronu.balin.examples.screenshots package

Best Balin code snippet using com.github.epadronu.balin.examples.screenshots.BaseTest

Run Balin automation tests on LambdaTest cloud grid

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

ScreenshotsTest.kt

Source: ScreenshotsTest.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.examples.screenshots
19/* ***************************************************************************/
20
21/* ***************************************************************************/
22import com.github.epadronu.balin.core.Browser
23import org.testng.Assert
24import org.testng.annotations.Listeners
25import org.testng.annotations.Test
26/* ***************************************************************************/
27
28/* ***************************************************************************/
29@Listeners(TestListener::class)
30class ScreenshotsTest : BaseTest() {
31
32    @Test
33    fun `Navigate to DuckDuckGo's index page`() {
34        Browser.drive({ webDriver }, autoQuit = false) {
35            get("https://www.duckduckgo.com")
36
37            Assert.assertEquals(title, "DuckDuckGo — Privacy, simplified.")
38        }
39    }
40
41    @Test
42    fun `Navigate to Searx's index page`() {
43        Browser.drive({ webDriver }, autoQuit = false) {
44            get("https://www.searx.me")
45
46            Assert.assertEquals(title, "searx.me")
47        }
48    }
49}
50/* ***************************************************************************/
51
Full Screen

BaseTest.kt

Source: BaseTest.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.examples.screenshots
19/* ***************************************************************************/
20
21/* ***************************************************************************/
22import com.github.epadronu.balin.utils.ThreadLocalDelegate
23import org.openqa.selenium.WebDriver
24import org.openqa.selenium.firefox.FirefoxDriver
25import org.testng.annotations.AfterMethod
26import org.testng.annotations.BeforeClass
27import org.testng.annotations.BeforeMethod
28/* ***************************************************************************/
29
30/* ***************************************************************************/
31open class BaseTest {
32
33    var webDriver: WebDriver by ThreadLocalDelegate()
34
35    @BeforeClass
36    fun `configure the driver`() {
37        /* You may need to provide the path for Firefox as well as for the gecko-driver
38         * is you wish to run the test
39         */
40    }
41
42    @BeforeMethod
43    fun `create the driver`() {
44        webDriver = FirefoxDriver()
45    }
46
47    @AfterMethod
48    fun `quit the driver`() {
49        webDriver.quit()
50    }
51}
52/* ***************************************************************************/
53
Full Screen

TestListener.kt

Source: TestListener.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.examples.screenshots
19/* ***************************************************************************/
20
21/* ***************************************************************************/
22import io.qameta.allure.Allure
23import org.openqa.selenium.OutputType
24import org.openqa.selenium.TakesScreenshot
25import org.testng.ITestListener
26import org.testng.ITestResult
27import org.testng.TestListenerAdapter
28/* ***************************************************************************/
29
30/* ***************************************************************************/
31class TestListener(listener: ITestListener = TestListenerAdapter()) : BaseTest(), ITestListener by listener {
32
33    override fun onTestSuccess(result: ITestResult) {
34        takeScreenshots(result)
35    }
36
37    override fun onTestFailure(result: ITestResult) {
38        takeScreenshots(result)
39    }
40
41    private fun takeScreenshots(result: ITestResult) {
42        val takesScreenshot = (result.instance as? BaseTest)?.webDriver as? TakesScreenshot
43
44        takesScreenshot?.run {
45            Allure.addByteAttachmentAsync("Screenshots", "image/png") {
46                getScreenshotAs(OutputType.BYTES)
47            }
48        }
49    }
50}
51/* ***************************************************************************/
52
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 BaseTest

    No methods found for this class 😞

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