Skip to content

Instantly share code, notes, and snippets.

View automationhacks's full-sized avatar

Gaurav Singh automationhacks

View GitHub Profile
@BeforeMethod
fun givenBookingIsCreated(testParams: Array<Any>) {
val vehicleType = testParams[0] as VehicleType
orderId = booking.makeBooking(vehicleType)
}
class SetupTeardownWithDataProvider {
private lateinit var vehicleType: VehicleType
private lateinit var orderId: String
private val booking = Booking()
@DataProvider
fun getVehicleTypes(): MutableIterator<Array<Any>> {
val vehicles = arrayListOf<Array<Any>>()
vehicles.add(arrayOf(VehicleType.CAR))
@automationhacks
automationhacks / BookingTestWithCancellation.kt
Created February 22, 2020 03:08
Adding BookingTest with cancellation option as well
class SetupTeardownWithDataProvider {
@DataProvider
fun getVehicleTypes(): MutableIterator<Array<Any>> {
val vehicles = arrayListOf<Array<Any>>()
vehicles.add(arrayOf(VehicleType.CAR))
vehicles.add(arrayOf(VehicleType.CAR_XL))
return vehicles.iterator()
}
@automationhacks
automationhacks / BookingCreationWithDataProviders.kt
Created February 22, 2020 03:03
Use of data providers to run the same test with different data
class SetupTeardownWithDataProvider {
@DataProvider
fun getVehicleTypes(): MutableIterator<Array<Any>> {
val vehicles = arrayListOf<Array<Any>>()
vehicles.add(arrayOf(VehicleType.CAR))
vehicles.add(arrayOf(VehicleType.CAR_XL))
return vehicles.iterator()
}
@automationhacks
automationhacks / BookingCreationTest.kt
Last active February 22, 2020 02:57
Simple test to make a booking and assert if it is created.
class SetupTeardownWithDataProvider {
@Test
fun testBookingCreation() {
val vehicleType = VehicleType.CAR_XL
val booking = Booking()
val orderId = booking.makeBooking(vehicleType)
val isBookingCreated = booking.doesBookingExists(vehicleType, orderId)
Assert.assertNotNull(isBookingCreated)
@automationhacks
automationhacks / Booking.kt
Created February 22, 2020 02:47
Simple class which models a booking application with booking and cancellation flow
enum class VehicleType() {
CAR,
CAR_XL
}
class BookingNotFound(message: String) : Exception(message)
class Booking {
companion object {
@automationhacks
automationhacks / build.gradle
Created January 9, 2020 00:30
Additional of listeners in test tasks
task runTests(type : Test) {
useTestNG() {
testLogging.showStandardStreams = true
listeners << "testFrameworks.testNG.logging.Listener"
includeGroups System.getProperty('tag', 'NONE')
}
}
@automationhacks
automationhacks / Listener.kt
Last active January 9, 2020 00:46
An implementation of TestListenerAdapter class with a custom implementation
class Listener : TestListenerAdapter() {
override fun onStart(context: ITestContext) {
Logger.log("Beginning test suite: ${context.outputDirectory}")
}
override fun onFinish(context: ITestContext?) {}
override fun onTestSkipped(result: ITestResult?) {}
override fun onTestStart(result: ITestResult) {
super.onTestStart(result)
> Task :runTests FAILED
Gradle suite > Gradle test > testFrameworks.testNG.logging.LoggingTests.when_CreditedSalary_ShouldBeGreater_ThanBase STANDARD_OUT
Checking that credited salary is ok
Gradle suite > Gradle test > testFrameworks.testNG.logging.LoggingTests.when_salaryIsNotCredited STANDARD_OUT
Checking that salary is not credited
Gradle suite > Gradle test > testFrameworks.testNG.logging.LoggingTests.when_salaryIsNotCredited FAILED
java.lang.AssertionError at Logging.kt:84
@automationhacks
automationhacks / Logger.kt
Created January 8, 2020 16:30
Simple wrapper over testNG reported.log method
object Logger {
fun log(msg: String, stdOut: Boolean = true) {
Reporter.log(msg, stdOut)
}
}