9

I want to achieve some use cases in which:

I want to perform some tasks that require manual intervention before kicking in automation execution. For instance, I need to manually launch the browser, navigate to the desired page, perform some manual tasks like entering captcha manually and then run the automation script to continue from there.

Debugging – Let's say we are working on a test script for a certain page (product checkout) in the application. But the script to reach that page (add to cart) is not ready yet. We can manually launch the browser and navigate to that page and then run the automation script.

Can someone help me to achieve this type of scenario?

5 Answers 5

12

You can use Chrome DevTools Protocol. Try with below steps:

  1. Add path of Chrome executable to environment variable PATH.
  2. Launch Chrome with custom flag, and open a port for remote debugging

    chrome.exe --remote-debugging-port=1111 --user-data-dir="C:\selenum\AutomationProfile"
    

You can now play with the browser manually, navigate to as many pages, perform actions and once you need your automation code to take charge, you may run your automation script.

  1. You just need to modify your Selenium script to make Selenium connect to that opened browser with below code.

    System.setProperty("webdriver.chrome.driver", "C:\\selenium\\chromedriver.exe");
    chromeOptions options = new ChromeOptions();
    options.setExperimentalOption("debuggerAddress", "127.0.0.1:1111");
    WebDriver driver = new ChromeDriver(options);`
    

Reference

4

You can use JAINAM answer , or

As you are using java , you could add a pop window that pauses your test till you finishes the manual part and resumes the code.

import javax.swing.JOptionPane;

//your code

//Pop while doing, your manual stuff

  int choice = JOptionPane.showOptionDialog(null, 
      "Ready to resume the scripts?", 
      "Please confirm", 
      JOptionPane.YES_NO_OPTION, 
      JOptionPane.QUESTION_MESSAGE, 
      null, null, null);


//continue your code
4

I have substantially simpler approach/solution than JAINAM's answer.

When I needed similar "in the middle" manual actions, I added (in Python) break to Python debugger. Execution stopped, I did desired manual actions (you can even load another page) and then I resumed the execution. Easy-peazy.

2

I would go with debugging mode, because (response about Chrome won't do anything if you need to test app on IE/Edge/other browser not based on Chromium).

Case #1:

For instance, I need to manually launch the browser, navigate to the desired page, perform some manual tasks like entering captcha manually and then run the automation script to continue from there.

Run your script in Debug mode (from IntelliJ, Visual Studio or whatever you use), which should:

  1. Run browser automatically
  2. Navigate to desired page automatically
  3. Set breakpoint on empty step for entering captcha (no code there, just the step definition).
  4. Debugger will pause script allowing you to perform all manual stuff.
  5. Continue running the script once you are done with manual stuff

Case #2:

But the script to reach that page (add to cart) is not ready yet.

  1. Basically the same as scenario #1. Use empty step, set breakpoint and run script to perform manual tasks.

The main thing is that is really hard to connect to existing browser process via Selenium API.

PS. It's really easy to do this when you are using Gherkin (SpecFlow, Cucumber or Behave, depending on language you use for automation)

1

I'm not sure about Selenium picking up on your existing browser pages/session.

From the question I assume you need/want to run these tests locally and not in some virtual browser or server?
In that case, a different way you could achieve this is:

  • Take the script that you have, let it start a session in a browser and immediately afterwards include a sufficiently long pause (thread.sleep for example).
  • Use this waiting time to do whatever manual actions you need to do.
  • Let the script pick back up after you once the wait is over (ideally not too long after you are done with the manual stuff).

Except for you not starting the browser session, this should have more or less the same behavior as you described.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.