0

I am new to Selenium. I have written a simple script using Junit/Selenium that opens a browser, opens a URL and then quits the browser. But the script isn't working.

Although the browser is launched nothing happens after that. I read on-line that maybe I need to add the latest Selenium jar file in the package but that didn't help either!

package pack1;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class TC01 {


WebDriver driver;

@Before
public void launchBrowser(){

    driver = new FirefoxDriver();


    driver.manage().window().maximize();


    driver.get("http://www.gmail.com");
}

@Test
public void atTest(){

}

@After
public void quitBrowser(){
    driver.quit();
}

}
1

Try with this configuration: Firefox 47.1 or Firefox ESR 45.3.0

Firefox ESR download page

driver.navigate().to("http://sqa.stackexchange.com");

If you are using maven then try this at pom.xml

<dependencies>
    <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
    <scope>test</scope>
</dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.53.1</version>
    </dependency>
</dependencies>

If you want to check if all system variables are set properly.

GitHub | Ardesco/Selenium-Maven-Template

  • I have edited my question with the code. My Firefox version is 47.0.1 still the code isn't working. – Rohan Kalia Sep 18 '16 at 8:33
  • Are you using maven? Also did you tried to run "Ardesco/Selenium-Maven-Template" ? – Mobile QA Sep 18 '16 at 11:36
0

Just try this and give the feedback..

 package pack1;

 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.firefox.FirefoxDriver;

public class TC01 {


 WebDriver driver;

@Before
public void launchBrowser(){

 System.setProperty("webdriver.firefox.marionette","pathToGeckodriver");
   FirefoxDriver driver=new FirefoxDriver();


driver.manage().window().maximize();


driver.get("http://www.gmail.com");
 }

 @Test
 public void atTest(){

  }

  @After
  public void quitBrowser(){
  driver.quit();
  }

   }
0
  1. Check the driver version of it is compatible with Firefox version you are using
  2. Use system.set.property("marinotte", true)
  3. Use profile function before calling the URL
-2

Try this:

  1. initialize driver in @before
  2. and call driver.get() in @test

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.