mercredi 8 juillet 2015

Why does running automation tests in bulk more likely to give failed results in Geb?

I am writing a geb automation code that fills up a form to add a 'configuration' and then checks if the created 'configuration' is created or not and then finally delete the 'configuration' and then confirm the deletion.

The problem is that I have created different configurations seven times and the deletion sometimes won't work for 2 or 3 cases. Individually each of the test cases work fine.

Can anyone help me with it? And if there are any suggestions on making the code better then please inform me.

package vmcTest.tests

import org.junit.Test
import vmcTest.pages.*
import geb.Page.*


class AdminExportTest extends TestBase {
    int insideCount = 0
    boolean loopStatus = false

    def setup() { // called before each test
        int count = 0

        while(count<numberOfTrials) {
            count ++
            try {
                setup: 'Open VMC page'
                to VoltDBManagementCenterPage
                expect: 'to be on VMC page'
                at VoltDBManagementCenterPage

                when: 'click the Admin link (if needed)'
                page.openAdminPage()
                then: 'should be on Admin page'
                at AdminPage

                break
            } catch (org.openqa.selenium.ElementNotVisibleException e) {
                println("ElementNotVisibleException: Unable to Start the test")
                println("Retrying")
            }
        }
    }

    def "Verify Add Configuration for FILE created"() {
        String fileTestName     = page.overview.getFileTestName()
        String fileValueOne     = page.overview.getFileValueOne()
        String fileValueTwo     = page.overview.getFileValueTwo()
        String fileValueThree   = page.overview.getFileValueThree()

        when: 'Open Add ConfigurationPopup'
        page.overview.openAddConfigurationPopup()
        page.overview.textType.value("FILE")
        then: 'Check elements'
        waitFor(waitTime) { page.overview.addProperty.isDisplayed() }
        waitFor(waitTime) { page.overview.save.isDisplayed() }
        waitFor(waitTime) { page.overview.cancel.isDisplayed() }
        waitFor(waitTime) { page.overview.type.value().equals("type") }
        waitFor(waitTime) { page.overview.nonce.value().equals("nonce") }
        waitFor(waitTime) { page.overview.outdir.value().equals("outdir") }
        waitFor(waitTime) { page.overview.typeValue.isDisplayed() }
        waitFor(waitTime) { page.overview.nonceValue.isDisplayed() }
        waitFor(waitTime) { page.overview.outdirValue.isDisplayed() }

        when: 'Provide values for add configuration'
        page.overview.stream.value(fileTestName)
        page.overview.typeValue.value(fileValueOne)
        page.overview.nonceValue.value(fileValueTwo)
        page.overview.outdirValue.value(fileValueThree)
        then: 'Click Save'
        page.overview.clickSave()

        when: 'Expand export'
        page.overview.expandExport()
        then: 'Display the created FILE'
        waitFor(waitTime) { page.overview.fileName.isDisplayed() }
        println("Configuration created")

        when: 'Edit button is displayed'
        waitFor(waitTime) { page.overview.editExportConfiguration.isDisplayed() }
        then: 'Click edit button'
        page.overview.editExportConfiguration.click()

        when: 'Delete Configuration is displayed'
        page.overview.deleteConfiguration.isDisplayed()
        then: 'Click delete configuration'
        page.overview.deleteExportConfiguration()

        when: 'Expand export'
        page.overview.expandExport()
        then: 'Check for deleted'
        try {
            waitFor(waitTime) { page.overview.fileName.isDisplayed() }
        } catch(geb.waiting.WaitTimeoutException e) {
            println("Configuration deleted")
        }
    }

    def "Verify Add Configuration for JDBC created"() {
        String jdbcTestName = page.overview.getJdbcTestName()
        String jdbcValueOne = page.overview.getJdbcValueOne()
        String jdbcValueTwo = page.overview.getJdbcValueTwo()

        when: 'Open Add ConfigurationPopup'
        page.overview.openAddConfigurationPopup()
        page.overview.textType.value("JDBC")
        then: 'Check elements'
        waitFor(waitTime) { page.overview.addProperty.isDisplayed() }
        waitFor(waitTime) { page.overview.save.isDisplayed() }
        waitFor(waitTime) { page.overview.cancel.isDisplayed() }
        waitFor(waitTime) { page.overview.jdbcdriver.value().equals("jdbcdriver") }
        waitFor(waitTime) { page.overview.jdbcurl.value().equals("jdbcurl") }
        waitFor(waitTime) { page.overview.jdbcdriverValue.isDisplayed() }
        waitFor(waitTime) { page.overview.jdbcurlValue.isDisplayed() }

        when: 'Provide values for add configuration'
        page.overview.stream.value(jdbcTestName)
        page.overview.jdbcdriverValue.value(jdbcValueOne)
        page.overview.jdbcurlValue.value(jdbcValueTwo)
        then: 'Click Save'
        page.overview.clickSave()

        when: 'Expand export'
        page.overview.expandExport()
        then: 'Display the created JDBC'
        waitFor(waitTime) { page.overview.jdbcName.isDisplayed() }
        println("Configuration created")

        when: 'Edit button is displayed'
        waitFor(waitTime) { page.overview.editExportConfiguration.isDisplayed() }
        then: 'Click edit button'
        page.overview.editExportConfiguration.click()

        when: 'Delete Configuration is displayed'
        page.overview.deleteConfiguration.isDisplayed()
        then: 'Click delete configuration'
        page.overview.deleteExportConfiguration()

        when: 'Expand export'
        page.overview.expandExport()
        then: 'Check for deleted'
        try {
            waitFor(waitTime) { page.overview.jdbcName.isDisplayed() }
        } catch(geb.waiting.WaitTimeoutException e) {
            println("Configuration deleted")
        }
    }

    def "Verify Add Configuration for KAFKA created"() {
        String kafkaTestName = page.overview.getKafkaTestName()
        String metadataValue = page.overview.getMetadataValue()

        when: 'Open Add ConfigurationPopup'
        page.overview.openAddConfigurationPopup()
        page.overview.textType.value("KAFKA")
        then: 'Check elements'
        waitFor(waitTime) { page.overview.addProperty.isDisplayed() }
        waitFor(waitTime) { page.overview.save.isDisplayed() }
        waitFor(waitTime) { page.overview.cancel.isDisplayed() }
        waitFor(waitTime) { page.overview.metadatabroker.value().equals("metadata.broker.list") }
        waitFor(waitTime) { page.overview.metadatabrokerValue.isDisplayed() }

        when: 'Provide values for add configuration'
        page.overview.stream.value(kafkaTestName)
        page.overview.metadatabrokerValue.value(metadataValue)
        then: 'Click Save'
        page.overview.clickSave()

        when: 'Expand export'
        page.overview.expandExport()
        then: 'Display the created KAFKA'
        waitFor(waitTime) { page.overview.kafkaName.isDisplayed() }
        println("Configuration created")

        when: 'Edit button is displayed'
        waitFor(waitTime) { page.overview.editExportConfiguration.isDisplayed() }
        then: 'Click edit button'
        page.overview.editExportConfiguration.click()

        when: 'Delete Configuration is displayed'
        page.overview.deleteConfiguration.isDisplayed()
        then: 'Click delete configuration'
        page.overview.deleteExportConfiguration()

        when: 'Expand export'
        page.overview.expandExport()
        then: 'Check for deleted'
        try {
            waitFor(waitTime) { page.overview.kafkaName.isDisplayed() }
        } catch(geb.waiting.WaitTimeoutException e) {
            println("Configuration deleted")
        }
    }

    def "Verify Add Configuration for HTTP created"() {
        String httpTestName = page.overview.getHttpTestName()
        String endValue = page.overview.getEndValue()

        when: 'Open Add ConfigurationPopup'
        page.overview.openAddConfigurationPopup()
        page.overview.textType.value("HTTP")
        then: 'Check elements'
        waitFor(waitTime) { page.overview.addProperty.isDisplayed() }
        waitFor(waitTime) { page.overview.save.isDisplayed() }
        waitFor(waitTime) { page.overview.cancel.isDisplayed() }
        waitFor(waitTime) { page.overview.endpoint.value().equals("endpoint") }
        waitFor(waitTime) { page.overview.endpointValue.isDisplayed() }

        when: 'Provide values for add configuration'
        page.overview.stream.value(httpTestName)
        page.overview.endpointValue.value(endValue)
        then: 'Click Save'
        page.overview.clickSave()

        when: 'Expand export'
        page.overview.expandExport()
        then: 'Display the created HTTP'
        waitFor(waitTime) { page.overview.httpName.isDisplayed() }
        println("Configuration created")

        when: 'Edit button is displayed'
        waitFor(waitTime) { page.overview.editExportConfiguration.isDisplayed() }
        then: 'Click edit button'
        page.overview.editExportConfiguration.click()

        when: 'Delete Configuration is displayed'
        page.overview.deleteConfiguration.isDisplayed()
        then: 'Click delete configuration'
        page.overview.deleteExportConfiguration()

        when: 'Expand export'

        page.overview.expandExport()
        then: 'Check for deleted'
        try {
            waitFor(waitTime) { page.overview.httpName.isDisplayed() }
        } catch(geb.waiting.WaitTimeoutException e) {
            println("Configuration deleted")
        }
    }

    def "Verify Add Configuration for RABBITMQ/Verify Add Configuration for RABBITMQ broker.host created"() {
        String rabbitmqBrokerTestName = page.overview.getRabbitmqBrokerTestName()
        String brokerValue = page.overview.getBrokerValue()

        when: 'Open Add ConfigurationPopup'
        page.overview.openAddConfigurationPopup()
        page.overview.textType.value("RABBITMQ")
        then: 'Check elements'
        waitFor(waitTime) { page.overview.addProperty.isDisplayed() }
        waitFor(waitTime) { page.overview.save.isDisplayed() }
        waitFor(waitTime) { page.overview.cancel.isDisplayed() }
        waitFor(waitTime) { page.overview.rabbitMqValue.isDisplayed() }

        when: 'Provide values for add configuration'
        page.overview.stream.value(rabbitmqBrokerTestName)
        page.overview.rabbitMqValue.value(brokerValue)
        then: 'Click Save'
        page.overview.clickSave()

        when: 'Expand export'
        page.overview.expandExport()
        then: 'Display the created RABBITMQ'
        waitFor(waitTime) { page.overview.rabbitMqBrokerName.isDisplayed() }
        println("Configuration created")

        when: 'Edit button is displayed'
        waitFor(waitTime) { page.overview.editExportConfiguration.isDisplayed() }
        then: 'Click edit button'
        page.overview.editExportConfiguration.click()

        when: 'Delete Configuration is displayed'
        page.overview.deleteConfiguration.isDisplayed()
        then: 'Click delete configuration'
        page.overview.deleteExportConfiguration()

        when: 'Expand export'
        page.overview.expandExport()
        then: 'Check for deleted'
        try {
            waitFor(waitTime) { page.overview.rabbitMqBrokerName.isDisplayed() }
        } catch(geb.waiting.WaitTimeoutException e) {
            println("Configuration deleted")
        }
    }

    def "Verify Add Configuration for RABBITMQ amqp.uri created"() {
        String rabbitmqAmqpTestName = page.overview.getRabbitmqAmqpTestName()
        String amqpValue = page.overview.getAmqpValue()

        when: 'Open Add ConfigurationPopup'
        page.overview.openAddConfigurationPopup()
        page.overview.textType.value("RABBITMQ")
        page.overview.rabbitMq.value("amqp.uri")
        then: 'Check elements'
        waitFor(waitTime) { page.overview.addProperty.isDisplayed() }
        waitFor(waitTime) { page.overview.save.isDisplayed() }
        waitFor(waitTime) { page.overview.cancel.isDisplayed() }
        waitFor(waitTime) { page.overview.rabbitMqValue.isDisplayed() }

        when: 'Provide values for add configuration'
        page.overview.stream.value(rabbitmqAmqpTestName)
        page.overview.rabbitMqValue.value(amqpValue)
        then: 'Click Save'
        page.overview.clickSave()

        when: 'Expand export'
        page.overview.expandExport()
        then: 'Display the created RABBITMQ'
        waitFor(waitTime) { page.overview.rabbitMqAmqpName.isDisplayed() }
        println("Configuration created")

        when: 'Edit button is displayed'
        waitFor(waitTime) { page.overview.editExportConfiguration.isDisplayed() }
        then: 'Click edit button'
        page.overview.editExportConfiguration.click()

        when: 'Delete Configuration is displayed'
        page.overview.deleteConfiguration.isDisplayed()
        then: 'Click delete configuration'
        page.overview.deleteExportConfiguration()

        when: 'Expand export'
        page.overview.expandExport()
        then: 'Check for deleted'
        try {
            waitFor(waitTime) { page.overview.rabbitMqAmpqName.isDisplayed() }
        } catch(geb.waiting.WaitTimeoutException e) {
            println("Configuration deleted")
        }
    }

    def "Verify Add Configuration for CUSTOM created"() {
        String customTestName = page.overview.getCustomTestName()
        String customConnectorClass = page.overview.getCustomConnectorClass()

        when: 'Open Add ConfigurationPopup'
        page.overview.openAddConfigurationPopup()
        page.overview.textType.value("CUSTOM")
        then: 'Check elements'
        waitFor(waitTime) { page.overview.addProperty.isDisplayed() }
        waitFor(waitTime) { page.overview.save.isDisplayed() }
        waitFor(waitTime) { page.overview.cancel.isDisplayed() }
        waitFor(waitTime) { page.overview.exportConnectorClass.isDisplayed() }

        when: 'Provide values for add configuration'
        page.overview.stream.value(customTestName)
        page.overview.exportConnectorClass.value(customConnectorClass)
        then: 'Click Save'
        page.overview.clickSave()

        when: 'Expand export'
        page.overview.expandExport()
        then: 'Display the created CUSTOM'
        waitFor(waitTime) { page.overview.customName.isDisplayed() }
        println("Configuration created")

        when: 'Edit button is displayed'
        waitFor(waitTime) { page.overview.editExportConfiguration.isDisplayed() }
        then: 'Click edit button'
        page.overview.editExportConfiguration.click()

        when: 'Delete Configuration is displayed'
        page.overview.deleteConfiguration.isDisplayed()
        then: 'Click delete configuration'
        page.overview.deleteExportConfiguration()

        when: 'Expand export'
        page.overview.expandExport()
        then: 'Check for deleted'
        try {
            waitFor(waitTime) { page.overview.customName.isDisplayed() }
        } catch(geb.waiting.WaitTimeoutException e) {
            println("Configuration deleted")
        }
    }
}

The 'overview' is a module and the methods used in overview are given below. If I have anything missing then please inform me.

def boolean expandExport() {
    int count = 0
    if (checkIfExportIsExpanded() == false) {
        while(count<20) {
            count++
            try {
                export.click()
                if (checkIfExportIsExpanded() == true) {
                    break
                }
            } catch(geb.error.RequiredPageContentNotPresent e) {
                return false
            } catch(org.openqa.selenium.StaleElementReferenceException e) {
                return true
            }
        }
    }
}

 def boolean checkIfExportIsExpanded() {
    try {
        exportExpanded.isDisplayed()
        return true
    } catch(geb.error.RequiredPageContentNotPresent e) {
        return false
    } catch(org.openqa.selenium.StaleElementReferenceException e) {
        return true
    }
 }

def void clickSave() {
    int count = 0
    while(count<80) {
        count++
        try {
            save.click()
            !save.isDisplayed()
        } catch(geb.error.RequiredPageContentNotPresent e) {

        } catch(org.openqa.selenium.StaleElementReferenceException e) {

        }
    }

    count = 0
    while(count<80) {
        count++
        try {
            confirmyesbtn.click()
            !confirmyesbtn.isDisplayed()
        } catch(geb.error.RequiredPageContentNotPresent e) {

        } catch(org.openqa.selenium.StaleElementReferenceException e) {

        }
    }
}

Aucun commentaire:

Enregistrer un commentaire