Capability of using Karate along with selenium webdriver

I started using Karate one week back and this is my first question. I used to write web service tests using Spock & groovy, Rest assured & cucumber. When I came across Karate I felt it's really interesting. Thank you for your huge effort.

I found Karate really capable and satisfying my needs to automated Json services. However, I would like to know some more details on this. I use another framework along with groovy, Spock and Java. In my scenario, I need to send a json request, get the transaction id from the response and then execute the UI test using selenium web driver. How can I easily integrate Karate tests with selenium web driver? This is a sample scenario including web service and UI in spock

    given: "Submit  Request and get valid response"
    getResponse("request.template", "/mypersonal")
    assert respStatus == 200
    String myOrderID = getValueFromResponse(orderId)
    verifyMyOrder(myOrderID)

    when: "Start the browser for executing the functionality and Navigate to app"
    WebDriver driver = DriverFactory.getInstance().getWebDriver()
    ObjectFactory oFctry = new ObjectFactory(driver)
    driver.navigate().to(url)
    oFctry.uLogin()
    oFctry.navigateToPersonalFile()

    then: "Validate the File"
    oFctry.searchInInDirectory(myOrderID)
    oFctry.navigateToProductDetailsPage(myOrderID)

    cleanup: "Close the chrome browser"
    DriverFactory.getInstance().removeDriver()

You have 2 options, call Selenium driver from Karate or call Karate via the Java API.

  • Example of mixing Java code using a Java library into a Karate test (JDBC in this case): dogs.feature. Also refer to how to call Java in the documentation.
  • Documentation for how to call Karate from Java: Java API

Personally, I prefer option 1 - which is what you have been doing with Spock.

EDIT: Karate now supports Web Browser automation, so you don't need Selenium anymore: The world needs an alternative to Selenium - so we built one