Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
1.1k views
in Selenium by Contributing Tester (14 points)
Hi ,

I am running 2 testcases on chrome and firefox
It start with 1 st testcase on chrome and  firefox parallely then once chrome completed
and close the browser mean while firefox session will go off and
start 2nd testcase on both chrome and firefox browser.

1st firefox browser wont run whole testcase execution

Can you suggest any solution ?

1 Answer

0 like 0 dislike
by The go-to Tester (181 points)
selected by
 
Best answer
Problem shows that your webdriver instance is being. It looks like either you are making your webdriver variable as static. Batter approach is to delcare and define webdriver instance inside @Test method.

 

Can you post your code which you're using to initiate webdriver object? It will help to provide detailed solution.
by Contributing Tester (14 points)
driver variable getting null, cant proceed to execution of process.
by The go-to Tester (181 points)
i think you should debug your code. What values you are passing for browser and URL?
by Contributing Tester (14 points)
hi,
i have debugged and solved , but same issue facing .

public WebDriver openBrowser(String vBrowser, String vHubUrl,WebDriver driver) throws IOException, InterruptedException {
        //browsertype browserType = browsertype.valueOf(vBrowser);
        //String userDir = System.getProperty("user.dir");
        //StringBuilder filename = new StringBuilder();
        DesiredCapabilities capability = null;
        switch (browsertype.valueOf(vBrowser)) {
        case IE:
            capability = DesiredCapabilities.internetExplorer();
            capability.setBrowserName("internet explorer");
            capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
            capability.setPlatform(org.openqa.selenium.Platform.WINDOWS);
            capability.setCapability(
                    InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
            capability.setJavascriptEnabled(true);
            break;

        case CHROME:

            capability = DesiredCapabilities.chrome();
            ChromeOptions options = new ChromeOptions();
            options.addArguments("test-type");
            options.addArguments("start-maximized");
            capability.setCapability(ChromeOptions.CAPABILITY, options);
            break;

        case FF:
            capability = DesiredCapabilities.firefox();
            break;

        case SAFARI:
            capability = DesiredCapabilities.safari();
            break;
        }
         
         driver = new RemoteWebDriver(new URL(vHubUrl), capability);
         System.out.println(driver);
         DriverSetUp setup= new DriverSetUp();
         setup.setDriver(driver);
         driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
         driver.manage().window().maximize();
         return setup.getDriver();
       
    }


public class DriverSetUp {

   private WebDriver driver;

    public WebDriver getDriver() {
        return driver;
    }

    public void setDriver(WebDriver driver) {
        this.driver = driver;
    }
   
}


Keyword code

WebDriver driver1;
    public void executeKeywords(WebDriver driver) throws Exception
    {   
   
        switch(vKW){
        case "openBrowser":
            driver1=openBrowser(vBrowser, vHubUrl,driver);
            implicitWait();
            break;
        case "enterSite":
            enterSite(driver1);
            break;
        case "closeBrowser":
            driverQuit(driver1);
            break;
    }
by Contributing Tester (14 points)
Without creating getter n setter class(driversetup), just return webDriver from open browser , same issue facing .
by The go-to Tester (181 points)
Creating get and set methods is not the solution. You need to create debug point at very beginning and understand where your code is flowing.


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...