Facing issue while running mvn clean test -DBrowser=Firefox in command prompt in cucumber framework

0

I am facing some issue while running my cucumber framework through command prompt. What I did , I create one generic utils package and there I implements Driver class and I used switch case for launching each driver. Now my motive is , I will not provide browser in properties file or anywhere else in my project. my browser will launch while I am passing the browser name(Ex: firefox, chrome, ie) from command prompt. I used to provide below command to run particular browser. syntax is: mvn clean test -DBrowser=Chrome. But problem is , this command is running perfectly while I am selecting chrome browser from command prompt. While Selecting Firefox I am getting error. error looks like version error. So what I did, I implements Driver class code such a way like not passing browser from command prompt. and run the code from eclipse that time it is launching Firefox driver. and then I run same code from command prompt that time I am getting error while launching Firefox. Can any one suggest me how to resolve this type of scenario?? Any leads would be appreciate :) Thanks in Advance :)

Below code for Driver class code:

public static WebDriver driver;
public static  Properties prop = new Properties();
public static Logger logger = Logger.getLogger(Driver.class.getName());
public static  WebDriver launchBrowser() {

    try {
        PropertyConfigurator.configure("./resourceLib/configuration/log4j.properties");
        logger.info("INFO Msg:=====================>Loading Properties file");
        prop.load(new FileInputStream("./resourceLib/configuration/configFile.properties"));

    }catch(Exception e) {
        logger.error("ERROR Msg:=====================>Error while loading properties file"+e);
        e.printStackTrace();
    }

    //browser identification should be user specific.
    String browserName=System.getProperty("Browser");
    System.out.println("Printing browser:=======>"+browserName);

    if(browserName==null) {
        browserName=System.getenv("Browser");
        System.out.println(browserName);

        if(browserName==null) {
            browserName="Firefox";
        }
    }

    switch (browserName) {
        case "Chrome" :

        try {
        System.setProperty(ChromeDriverService.CHROME_DRIVER_SILENT_OUTPUT_PROPERTY, "true");
        logger.info("INFO Msg:=====================> Launching Chrome browser");
        if(browserName.equals("Chrome")) {
        WebDriverManager.chromedriver().setup();
        driver=new ChromeDriver();
        driver.manage().window().maximize();
        driver.manage().deleteAllCookies();
        }else {
            logger.error("ERROR Msg:=====================> Error while executing chrome driver");
        }

        }catch (Exception e) {
            logger.error("ERROR Msg:=====================> Error while launching Chrome browser"+e);
            e.printStackTrace();
        }
        break;

        case "Firefox" :

        try {
        logger.info("INFO Msg:=====================> Launching Firefox browser");
        if(browserName.equals("Firefox")) {
        WebDriverManager.firefoxdriver().setup();
        driver=new FirefoxDriver();
        System.out.println("Hello this line should execute====>"+driver);
        driver.manage().window().maximize();
        driver.manage().deleteAllCookies();
        }else {
            logger.error("ERROR Msg:=====================> Error while executing firefox driver");
        }
        }catch (Exception e) {
            logger.error("ERROR Msg:=====================> Error while launching Firefox browser"+e);
            e.printStackTrace();
        }
        break;

        case "IE":

        try {
            logger.info("INFO Msg:=====================> Launching IE browser");
            if(browserName.equals("IE")) {
            WebDriverManager.iedriver().setup();
            driver=new InternetExplorerDriver();
            driver.manage().window().maximize();
            driver.manage().deleteAllCookies();
            }else {
                logger.error("ERROR Msg:=====================> Error while executing IE driver");
            }
            }catch (Exception e) {
                logger.error("ERROR Msg:=====================> Error while launching IE browser"+e);
                e.printStackTrace();
            }
        logger.error("ERROR Msg:=====================> Please choose the correct browser");
        break;

        default:
            try {
                logger.info("INFO Msg:=====================> Launching IE browser");
                WebDriverManager.firefoxdriver().setup();
                driver=new FirefoxDriver();
                driver.manage().window().maximize();
                driver.manage().deleteAllCookies();
                }catch (Exception e) {
                    logger.error("ERROR Msg:=====================> Error while launching Firefox browser"+e);
                    e.printStackTrace();
                }
                break;

    }

    return driver;
}

}

Below code for step defination class code:

@Before() 
public void setUp(Scenario scenario) {
    this.scenario=scenario;
    Report.setReport();
    try {
    logger.info("INFO Msg:===============>Launch the Browser");
    Driver.launchBrowser();
    logger.info("Executing Scenario :"+scenario.getName());
    }catch (Exception e) {
        logger.error("ERROR Msg:=============>Error While launcing browser ");
    }
}

//tear down method where browser should close
@After
public void tearDown(Scenario scenario) {
    String timeStamp=new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());
    scenario.write("Finished Scenario");


    if(scenario.isFailed()) {

        scenario.embed(((TakesScreenshot)Driver.driver).getScreenshotAs(OutputType.BYTES), "./report/screenshots/"+timeStamp+".png");
    }
    logger.info("Test Enviourment closed");
    Driver.driver.quit();
    Report.endReport();
}


@Given("^I want Login to the application$")
public void i_want_Login_to_the_application() throws Throwable {

    Report.createReport("Login to ActiTime Application and Validate Enter Time-Track heading should be available", "Login to ActiTime Application");
    loginfo=Report.createTesteport("Given", "I want Login to the application");
        try {
        loginfo.info("INFO Msg:===============>Launch AtiTime application");

        Driver.driver.get(prop.getProperty("actiTime_URL"));
        loginfo.info("AtiTime application launch properly");
    } catch (Exception e) {
        Report.tesepHandelStep("FAIL", loginfo, e);
        loginfo.error("ERROR Msg:=============>Error While launcing ActiTime application"+e);
    }
}

Below code is for runner class code:

@RunWith(Cucumber.class)
@CucumberOptions(features="./resourceLib/Features", glue= {"StepDefination"},
format= { "pretty","html:report/cucumberReports", "json:target/cucumberReports/cucumber.json"
    ,"junit:target/cucumberReports/cucumber.xml"},
tags= {"@SmokeTest"}, monochrome=true,plugin = ("json:target/cucumber- 
reports/CucumberTestReport.json"))



public class TestRunner {}

Getting Below Error:

05-01-2020 19:59:09 Driver.java INFO [main] GenericUtils.Driver 80 - INFO Msg:=====================> Launching Firefox browser May 01, 2020 7:59:09 PM java.util.prefs.WindowsPreferences WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5. [DEBUG] Preference firefox=74 (valid until 2020-05-02 00:25:12) [DEBUG] Preference firefox74=0.26.0 (valid until 2020-05-02 00:25:12) [INFO] Using geckodriver 0.26.0 (since Mozilla Firefox 74 is installed in your machine) [DEBUG] Driver geckodriver 0.26.0 found in cache [INFO] Exporting webdriver.gecko.driver as C:\Users\Admin.m2\repository\webdriver\geckodriver\win64\0.26.0\geckodriver.exe 05-01-2020 19:59:32 Driver.java ERROR [main] GenericUtils.Driver 91 - ERROR Msg:=====================> Error while launching Firefox browserorg.openqa.selenium.WebDrive rException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:45951 Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03' System info: host: 'ADMIN-PC', ip: '192.168.0.100', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_172' Driver info: driver.version: Driver org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:45951 Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03' System info: host: 'ADMIN-PC', ip: '192.168.0.100', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_172' Driver info: driver.version: Driver at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:92) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:131) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:147) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:125) at GenericUtils.Driver.launchBrowser(Driver.java:83) at StepDefination.Login_ActiTime_And_Validate_EnterTimeTrackStep.setUp(Login_ActiTime_And_Validate_EnterTimeTrackStep.java:75) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at cucumber.runtime.Utils$1.call(Utils.java:40) at cucumber.runtime.Timeout.timeout(Timeout.java:16) at cucumber.runtime.Utils.invoke(Utils.java:34) at cucumber.runtime.java.JavaHookDefinition.execute(JavaHookDefinition.java:60) at cucumber.runtime.Runtime.runHookIfTagsMatch(Runtime.java:224) at cucumber.runtime.Runtime.runHooks(Runtime.java:212) at cucumber.runtime.Runtime.runBeforeHooks(Runtime.java:202) at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:40) at cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:102) at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63) at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18) at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329) at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293) at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) at org.junit.runners.ParentRunner.run(ParentRunner.java:413) at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:70) at cucumber.api.junit.Cucumber.runChild(Cucumber.java:95) at cucumber.api.junit.Cucumber.runChild(Cucumber.java:38) at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329) at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293) at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) at org.junit.runners.ParentRunner.run(ParentRunner.java:413) at cucumber.api.junit.Cucumber.run(Cucumber.java:100) at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:365) at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:273) at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:238) at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:159) at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:377) at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:138) at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:465) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:451) Caused by: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:45951 at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:247) at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:165) at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:257) at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135) at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114) at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200) at okhttp3.RealCall.execute(RealCall.java:77) at org.openqa.selenium.remote.internal.OkHttpClient.execute(OkHttpClient.java:103) at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:105) at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:74) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136) at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83) ... 48 more

java
selenium-webdriver
cucumber
asked on Stack Overflow May 1, 2020 by nilava pal • edited May 1, 2020 by nilava pal

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0