Run Balin automation tests on LambdaTest cloud grid
Perform automation testing on 3000+ real desktop and mobile devices online.
/******************************************************************************
* Copyright 2016 Edinson E. Padrón Urdaneta
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
/* ***************************************************************************/
package com.github.epadronu.balin.examples.screenshots
/* ***************************************************************************/
/* ***************************************************************************/
import com.github.epadronu.balin.core.Browser
import org.testng.Assert
import org.testng.annotations.Listeners
import org.testng.annotations.Test
/* ***************************************************************************/
/* ***************************************************************************/
@Listeners(TestListener::class)
class ScreenshotsTest : BaseTest() {
@Test
fun `Navigate to DuckDuckGo's index page`() {
Browser.drive({ webDriver }, autoQuit = false) {
get("https://www.duckduckgo.com")
Assert.assertEquals(title, "DuckDuckGo â Privacy, simplified.")
}
}
@Test
fun `Navigate to Searx's index page`() {
Browser.drive({ webDriver }, autoQuit = false) {
get("https://www.searx.me")
Assert.assertEquals(title, "searx.me")
}
}
}
/* ***************************************************************************/
/******************************************************************************
* Copyright 2016 Edinson E. Padrón Urdaneta
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
/* ***************************************************************************/
package com.github.epadronu.balin.examples.screenshots
/* ***************************************************************************/
/* ***************************************************************************/
import com.github.epadronu.balin.utils.ThreadLocalDelegate
import org.openqa.selenium.WebDriver
import org.openqa.selenium.firefox.FirefoxDriver
import org.testng.annotations.AfterMethod
import org.testng.annotations.BeforeClass
import org.testng.annotations.BeforeMethod
/* ***************************************************************************/
/* ***************************************************************************/
open class BaseTest {
var webDriver: WebDriver by ThreadLocalDelegate()
@BeforeClass
fun `configure the driver`() {
/* You may need to provide the path for Firefox as well as for the gecko-driver
* is you wish to run the test
*/
}
@BeforeMethod
fun `create the driver`() {
webDriver = FirefoxDriver()
}
@AfterMethod
fun `quit the driver`() {
webDriver.quit()
}
}
/* ***************************************************************************/
/******************************************************************************
* Copyright 2016 Edinson E. Padrón Urdaneta
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
/* ***************************************************************************/
package com.github.epadronu.balin.examples.screenshots
/* ***************************************************************************/
/* ***************************************************************************/
import io.qameta.allure.Allure
import org.openqa.selenium.OutputType
import org.openqa.selenium.TakesScreenshot
import org.testng.ITestListener
import org.testng.ITestResult
import org.testng.TestListenerAdapter
/* ***************************************************************************/
/* ***************************************************************************/
class TestListener(listener: ITestListener = TestListenerAdapter()) : BaseTest(), ITestListener by listener {
override fun onTestSuccess(result: ITestResult) {
takeScreenshots(result)
}
override fun onTestFailure(result: ITestResult) {
takeScreenshots(result)
}
private fun takeScreenshots(result: ITestResult) {
val takesScreenshot = (result.instance as? BaseTest)?.webDriver as? TakesScreenshot
takesScreenshot?.run {
Allure.addByteAttachmentAsync("Screenshots", "image/png") {
getScreenshotAs(OutputType.BYTES)
}
}
}
}
/* ***************************************************************************/
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.