Capability of using Karate along with selenium webdriver
Asked Answered
L

1

3

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()
Lankford answered 10/11, 2017 at 18:50 Comment(0)
P
3

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

Psychotomimetic answered 11/11, 2017 at 1:8 Comment(1)
Thank you, peter. We are working on this. We will post the updates and notes about the solutions we implement. We are trying to implement the first option. We also trying to understand how the webdriver assertions will be displayed in the results while using this way. Mainly at the time of failuresLankford

© 2022 - 2024 — McMap. All rights reserved.