-1
driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get(URL);

I'm trying to run my test in Firefox using version 46.0.1 and webdriver 2.53.0 but when I run the test I see Firefox start and then close very quickly. I've got all other browsers to work and am at a loss as to what I'm missing here.

  @BeforeClass
    public static void setUp() {
        System.out.println("****************");
        System.out.println("launching Browser");
driver = new FirefoxDriver();
    driver.get("url");

   @Test
    public void testPageTitleInBrowser() {

FirstPage firstPage = PageFactory.initElements(driver, FirstPage.class); firstPage

                 .logIn(username, password)
                .clickHolidayLink()
                .completeHolidayFormAndSubmit("12/05/2016");


    }

@AfterClass
    public static void tearDown() {
        if (driver != null) {
            System.out.println("Closing browser");
            driver.quit();
        }
    }

Mainpage has been changed to firstpage

import com.google.common.annotations.VisibleForTesting;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

import static Internal.BaseTest.driver;


public class FirstPage {


    @VisibleForTesting
    @FindBy(id = "ctl00_MCPH_MainLogin_UserNameTextBox")
    WebElement usernameInput;

    @VisibleForTesting
    @FindBy(id = "ctl00_MCPH_MainLogin_PasswordTextBox")
    WebElement passwordInput;

    @VisibleForTesting
    @FindBy(id = "ctl00_MCPH_MainLogin_LoginButton")
    WebElement loginButton;


    public BookAHoliday logIn(String username, String password){
        usernameInput.sendKeys(username);
        passwordInput.sendKeys(password);
        loginButton.click();
        return PageFactory.initElements(driver, BookAHoliday.class);
    }
}
OhAye
  • 93
  • 1
  • 4
  • 12
  • can you please paste the complete code. – k.s. Karthik May 17 '16 at 15:14
  • That's everything in my @BeforeClass what else do you need? MainPage mainPage = PageFactory.initElements(driver, MainPage.class); mainPage // .logIn("username", "password") .clickHolidayLink() .completeHolidayFormAndSubmit("12/05/2016"); This is my Test – OhAye May 17 '16 at 15:15
  • Based on information provided, this is going to get closed as "cannot reproduce". Have a read through [mcve]. – SiKing May 17 '16 at 15:44
  • did you got any exception, if so plz paste it – murali selenium May 17 '16 at 16:26
  • No, no exception it just hangs and doesn't timeout. I do see Firefox open but it closes right away. In terms of evidence I really don't have much more I can provide – OhAye May 17 '16 at 16:27
  • hi do u have any @AfterClass defined where you have the code to quit the browser – Rajnish Kumar May 17 '16 at 17:16
  • Yes I do, have added the @Afterclass to the main question – OhAye May 17 '16 at 17:55
  • i think reinstalling firefox and updating to latest version of selenium will work,at my side its working fine – Rajnish Kumar May 17 '16 at 18:25

3 Answers3

1

As there is no test case written in the above code snippet, firefox driver will get opened in the @BeforeClass and as the condition driver != null is satisfied in @AfterClass, firefox is getting closed. This is expected behavior, as per your code.

k.s. Karthik
  • 731
  • 6
  • 16
  • So debugging the issue you're correct that driver is null. But I have added -Dwebdriver.firefox.bin="C:\Program Files (x86)\Mozilla Firefox\firefox.exe" in VM options for intelliJ. There is a test case written which I've updated in the main question. – OhAye May 31 '16 at 11:26
  • can you please give me the MainPage class – k.s. Karthik May 31 '16 at 12:18
  • Added to main question – OhAye May 31 '16 at 12:45
  • Is this code trying to perform login operation or is it getting exited after launching it. Also, is this code working with other browsers? – k.s. Karthik May 31 '16 at 13:52
  • Its performing the login after the page has loaded. And yes it works for other browsers. Driver is not null when I use chrome or IE but seems to show as null when I use firefox. Also the driver never quits it just continues to run until I press stop. It looks like firefox starts for a second and closes rights away. – OhAye May 31 '16 at 13:54
  • Are you getting any error message? Also please try to put some wait in the logIn, clickHolidayLink, and completeHolidayFormAndSubmit methods – k.s. Karthik May 31 '16 at 14:11
  • No I dont get any error messages, I have waits in those methods but the test does not get as far as that. I did notice when I step into the Firefoxdriver() method it does show logger as null as well in RemoteWebDriver.java – OhAye May 31 '16 at 15:26
0

Add Thread.sleep(3000); before driver.quit();or remove driver.quit();and see what happens. As you are not doing much in your test, it may be behaving correctly.

abhijeet kanade
  • 161
  • 1
  • 10
0

I was facing a similar problem. Firefox would open and then close without even navigating to the specified URL. Upgrade to the latest selenium(2.53) fixed the problem.

There was another instance where even the upgraded did not work. This was due to some plugins that my organization had installed.

Temporarily rename the "distribution" directory that is present in the location where Firefox is installed, and see if this works. Ex: C:\Program Files (x86)\Mozilla Firefox\ or /usr/lib/firefox/ This worked for me.

Pradhan
  • 518
  • 4
  • 14
  • Hmm I'll give that a go – OhAye May 18 '16 at 10:06
  • I can't seem to find the distribution folder. It doesnt seem to be hidden and its not in either of the areas you mentioned. – OhAye May 18 '16 at 10:18
  • I think they have removed the distribution folder from the newer versions of Firefox – OhAye May 18 '16 at 10:22
  • Which version of selenium webdriver ? Which OS are you running this on ? Can you pastebin the Firefox install directory tree structure (use `tree /A` on windows `find` on linux)? – Pradhan May 18 '16 at 11:46
  • I'm using 2.53.0 selenium. And am running on Windows 8. This is the Firefox directory C:\Program Files (x86)\Mozilla Firefox (is that what you wanted?) – OhAye May 18 '16 at 13:26
  • Open command prompt. Goto `C:\Program Files (x86)\Mozilla Firefox`. Run `tree /a > c:\ffdir.txt`. Share the contents of this file. (you could use pastebin . com) – Pradhan May 18 '16 at 13:42
  • It looks fine to me. May be its something else that is causing this. Try running a simple java program with just the FirefoxDriver launch a different url (http :// stackoverflow . com), sleep for 5 seconds, then quit. – Pradhan May 20 '16 at 02:22
  • It does look like my driver is null so anything I try wont work unless I can get the driver to recognise the firefox driver – OhAye May 31 '16 at 11:28