1

I am trying to automate the below scenario using karate UI automation

Feature: Background: Using callonce and calling the login feature which launches the url and enter username/passowrd and click login.

Scenario: Perform some steps with the open browser

Scenario: Perform some other steps with the same browser

Problem: first scenario executes perfectly and the browser remains open after that. But on executing second scenario, it is not able to identify the objects in the opened browser

Note: I have configured the driver in Karate-config.js as below karate.configure('driver', { type: 'chrome', executable: 'C:\Program Files\Google\Chrome\Application\chrome.exe',addOptions: ["--remote-allow-origins=*"]});

As a workaround, i tried using call instead of callonce while calling the login feature in background. In that case both scenario works fine but the browser closes after first scenario and login action is called again before starting the second scenario. I am trying to avoid this multiple login steps to reduce the execution time

  • 2 things. `callonce` is absolutely not supported for the UI. karate is deliberately designed this way because teams want tests to run in parallel, so trying to re-use the same login session is not possible. I suggest you look into signing in via the API if you really want to go to the next level: https://github.com/karatelabs/karate/tree/develop/karate-core#hybrid-tests - in which case you can easily use `karate.callSingle()` - but if you really want one browser instance, please see: https://stackoverflow.com/a/60387907/143475 – Peter Thomas Aug 18 '23 at 12:50
  • Hi @PeterThomas - Thanks for the prompt response. Below is my requirement. I have to login in to the browser - search for a number and navigate to that page, click on the download link from that page and save the pdf in a location. Then using pdfcompare i have to compare the downloaded pdf with the expected pdf. This i have to repeat for different numbers. The complete flow is working for me but i have to login each time to search for that particular number. Trying to reduce time by avoiding the login steps. Any suggestions for this scenario –  Aug 18 '23 at 14:06
  • I have nothing to add to my previous comment. please read the links and spend some time understanding the options. I think this link may give you the best solution for your needs, but you need to try it and validate: https://stackoverflow.com/a/66762430/143475 – Peter Thomas Aug 19 '23 at 07:03

0 Answers0