Error While Running Parallel Make

Error while running parallel make

If any program called by make returns with an error, the return code of make will not be zero. So after calling make you could just check the return code to see if an error occurred. On bash (and many other shells like zsh) you could do the following:

# make
....
# echo $?

The echo will print 0 if anything was ok and will print something else if it wasn't.

You could also run the check from inside a shell script:

make
if [ $? -eq 0 ]; then
echo "Everything OK"
else
echo "Something went wrong!"
fi

If you need the exact error message the easiest way is to redirect the output from make to some file and grep for the error if execution failed.

But the way I usually do this is to run make in parallel and re-execute it with -j1 if something went wrong so I will get a clean error message. I guess this could be put into a shell script using the technique above.

Ger error when trying to run parallel builds on maven release prepare and perform task?

Thanks @khmarbaise for suggesting the fix. This can be solved with latest maven version and can be seen described in the release notes for version 3.6.1

http://maven.apache.org/docs/3.6.1/release-notes.html

Warning forced in submake in parallel execution of make

Usually this message occurres if you call make from your Makefile not by the variable $(MAKE)

Example:

Change


foo:
cd foo/ && make foo

to


foo:
cd foo && $(MAKE) foo

Parallel execution of test throws exception when parallel is set to true on DataProvider - TestNG

The problem lies in your test code. Your webdriver instances are getting shared across test methods when you run tests in parallel and powered by a data provider.

Here's a fixed version of your BaseTest and BrowserDriverFactory to include thread safety.

import java.lang.reflect.Method;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.ITestContext;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;

public class BaseTest {
private static final ThreadLocal<WebDriver> drivers = new ThreadLocal<>();
public WebDriverWait wait;
protected FirefoxProfile profile;
protected String url = "http://www.qaclickacademy.com/";

protected String testSuiteName;
protected String testName;
protected String testMethodName;

public WebDriver getDriver() {
return drivers.get();
}

@BeforeMethod()
public void setUp(Method method, ITestContext ctx) {
String testName = ctx.getCurrentXmlTest().getName();

WebDriver driver = BrowserDriverFactory.createDriver("firefox");
drivers.set(driver);
driver.get(url);

driver.manage().window().maximize();
wait = new WebDriverWait(driver, 5);

this.testSuiteName = ctx.getSuite().getName();
this.testName = testName;
this.testMethodName = method.getName();
}

@AfterMethod(alwaysRun = true)
public void tearDown(ITestResult result) {
getDriver().quit();
drivers.remove();
}
}

BrowserDriverFactory.java

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;

public class BrowserDriverFactory {

public static WebDriver createDriver(String browser) {
System.err.println("Create driver: " + browser);

if (browser.equals("chrome")) {
System.setProperty("webdriver.chrome.driver", "src/main/resources/chromedriver.exe");
return new ChromeDriver();
} else if (browser.equals("firefox")) {
System.setProperty("webdriver.gecko.driver", "src/main/resources/geckodriver.exe");
FirefoxOptions options = new FirefoxOptions();
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.helperApps.neverAsk.openFile", "application/octet-stream");
options.setProfile(profile);
return new FirefoxDriver(options);
}
System.out.println("Do not know how to start: " + browser + ", starting chrome.");
System.setProperty("webdriver.chrome.driver", "src/main/resources/chromedriver.exe");
return new ChromeDriver();
}
}

Now in all the test methods of test classes that extend BaseTest whenever you need access to the driver object, you would get it by invoking getDriver() method.

You can find a full fledge explanation and some more explanation around this in this blog of mine: https://rationaleemotions.com/parallel_webdriver_executions_using_testng/

I also created a library that abstracts out the webdriver lifecycle management and makes it even more simpler for you via a custom annotation.

Take a look at https://github.com/rationaleEmotions/autospawn

Selenium handles ProtocolHandshake error while running tests parallel

You can use ThreadLocal class to make your webdriver Threadsafe

private ThreadLocal<WebDriver> webdriver = new ThreadLocal<WebDriver>();

@BeforeMethod
public void setUp() {
webdriver.set(driverManager.setupDriver("chrome"));
}

@Test(invocationCount = 5, threadPoolSize = 5)
public void testThreadPool() {
webdriver.get().get("http://www.google.com");
webdriver.get().findElement(By.name("q")).sendKeys("Amazon");
}

@AfterMethod
public void tearDown() {
webdriver.get().quit()
}

Edit : You will need to use BeforeMethod/AfterMethod in above context.



Related Topics



Leave a reply



Submit