To achieve parallel execution, I am updating my existing Junit project to .
The requirement here is to run one scenario in different browsers using TestNG

RunnerClass is as follows:

import org.junit.runner.RunWith;
import org.testng.annotations.Test;

import .api.CucumberOptions;
import .api.junit.;
import .api.testng.AbstractTestNGCucumberTests;

@RunWith(.)
@CucumberOptions(
        format   = {"pretty","html:target/cucumber", "json:target/cucumber.json","rerun:target/rerun_featureName.txt"},
        features = {"src/test/resources/com.philips.rs.testcases.sanity.ui.features/02_adUserLogin.feature"},                               
        strict = true,
        monochrome = true,
        glue = {"com.philips.rs.ui.stepdefs","com.philips.rs.backend.stepdefs","com.philips.rs.utils"},
        tags = {"@rsUITest","@sanity",}

        )

@Test
public  PBPRunnerSanityUITest extends AbstractTestNGCucumberTests {

}

The class where browser is fetched.

public class WebDriverFactory {

    public static WebDriver driver = null;
    public static String currentBrowser = null;
    final static int TIMEOUT1 = 30;
    final static int TIMEOUT2 = 90;
    final static int TIMEOUT3 = 120;

    @Parameters("browser")
    @BeforeTest
    public static WebDriver createDriver(String browser) throws InterruptedException, MalformedURLException, IOException {

        currentBrowser = browser;
        DesiredCapabilities capabilities = new DesiredCapabilities() ;

        switch (browser) {

        case "IE_LOCAL":
            System.setProperty("webdriver.ie.driver","./driver_exe/IEDriverServer.exe");
            capabilities = DesiredCapabilities.internetExplorer();
            capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
            driver = new InternetExplorerDriver(capabilities);
            break;
        case "IE_REMOTE":

            break;
        case "CHROME_LOCAL":
            System.setProperty("webdriver.chrome.driver","./driver_exe/chromedriver.exe");
            driver = new ChromeDriver();
            break;
        case "FIREFOX_LOCAL":       
            System.setProperty("webdriver.gecko.driver", "./driver_exe/geckodriver.exe");   
            FirefoxProfile profile = new FirefoxProfile();
            profile.setPreference("browser.download.folderList", 1);
            profile.setPreference("browser.download.manager.showWhenStarting", false);
            profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf,image/png,image/gif,application/json;charset=UTF-8,application/octet-stream; charset=utf-8,application/font-woff,text/csv");
            profile.setPreference( "pdfjs.disabled", true );
            capabilities.setCapability(FirefoxDriver.PROFILE, profile);
            capabilities.setAcceptInsecureCerts(true);
            driver = new FirefoxDriver(capabilities);
            break;
        case "CHROME_REMOTE":
            Runtime.getRuntime().exec("cmd /c start .\batchFiles\seleniumServer.bat");
            String nodeURL = "130.147.173.151:4444/wb/hub";
            capabilities = DesiredCapabilities.chrome();
            capabilities.setBrowserName("chrome");
            capabilities.setPlatform(Platform.WINDOWS);
            driver=new RemoteWebDriver(new URL(nodeURL), capabilities);         

        }
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

        return driver;
    }


    public WebDriver getDriver()
    {
        return driver;
    }


}

TestNG XML file looks as below :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="Suite" parallel="tests">

  <test name ="FirefoxTest">
  <parameter name= "browser" value ="firefox"/>
    <classes>
      <class name="com.philips.rs.application.setup.PBPRunnerSanityUITest"/>
    </classes>   
  </test> 

    <test name ="IETest">
  <parameter name= "browser" value ="ie"/>
    <classes>
      <class name="com.philips.rs.application.setup.PBPRunnerSanityUITest"/>
    </classes>  
  </test>

</suite> 

I am not able to able to fetch parameter value “Browser” in webDriverFactory Class, when Test is ran, code is not reached till WebDriverFactory .
Please let me where it is going wrong.



Source link https://sqa.stackexchange.com/questions/33298/-to--the-parameter-value-inside-a-class-using-testng

LEAVE A REPLY

Please enter your comment!
Please enter your name here