0

I'm trying to run the LeanFT tests parallely using TestNg XML in Chrome browser.

It runs fine, but it opens every test session in the same browser causing issues with cookies for logins and log outs.

Example:

I'm running test from TestNG XML with parallel="tests" thread-count="2" and launching the browser in LeanFT with

public Browser getbrowser() {
  Browser browser = null;
  browser = BrowserFactory.launch(BrowserType.CHROME);
  browser.clearCache();
  return browser;
}

So every time I run the test from TestNG XML in parallel, all tests opens up in the same browser causing cookies issue, as I have browser.clearCache() in getbrowser() method.

I want to run the LeanFT tests in parallel with each thread opening new instance of Chrome window and running parallely on the same machine.

Please share if any one has implemented the parallel execution for LeanFT in same machine.

Adelin
  • 7,809
  • 5
  • 37
  • 65
  • Please edit your question and add more context. What does your sample code look like, what is the error you are facing etc., Its not clear what you are asking. – Krishnan Mahadevan May 15 '18 at 15:35

1 Answers1

0

When you use BrowserFactory.launch, behind the scenes it's kind of like running

chrome about:blank

from the command line. You can try executing this in command line/terminal and you'll see that the first time, a new window will open, but the 2nd, 3rd and so on times it'll mean a new tab in the opened window.

This is a browser specific behavior. Sure enough, firefox differently from command line and, no wonder, .launch opens a new window on firefox from leanft as well.

To open a new window in chrome, a --new-window switch is needed. LeanFT is not prepared for that (yet), you'll have to run the command yourself.

chrome --new-window www.google.com

I'm sure you know how to start a process from Java but, for completeness of my answer, here's how to start a process from java. Essentially:

Process myProcess = Runtime.getRuntime().exec(command);

And then use BrowserFactory.attach, to attach to the opened window.

If you have to run multiple instances, you'll need to uniquelly identify them. Try opening new windows each time incrementing a variable like: https://www.google.com/search?q=dummy1

So:

  1. Window 1

    Process to start: chrome --new-window https://www.google.com/search?q=dummy1

    Description to use:

    BrowserFactory.attach(new BrowserDescription.Builder().title("dummy1 - Google Search").build());
    
  2. Window 2

    Process to start: chrome --new-window https://www.google.com/search?q=dummy2

    Description to use:

    BrowserFactory.attach(new BrowserDescription.Builder().title("dummy2 - Google Search").build());
    
  3. etc.

Adelin
  • 7,809
  • 5
  • 37
  • 65