We've got some good selenium tests running against Firefox with Play 2.1
http://www.playframework.com/documentation/api/2.0/scala/play/api/test/Helpers
However even though webdriver does support Internet Explorer, i dont see an IE helper. Is there any way around this?
Based on the Fluentlenium documentation, your test class should extend FluentTest. You can then simply override the getDefaultDriver() method to change the browser:
public class IntegrationTest extends FluentTest {
#Override
public WebDriver getDefaultDriver(){
return new InternetExplorerDriver();
}
}
You should be able to return any Selenium WebDriver in this method (only tested with IE and FF).
Related
I have created a java/selenium/cucumber automation framework with 4 feature files each testing different functional area's.
I can run each of these within Eclipse as feature files and they all run fine.
However I am trying to figure out how I can run them all as a JUnit test so that I can generate the extent reports.
I run the mainRunner class as a Junit test like ..
The first feature runs fine but then the next three do not. A chrome browser is opened for each of these but
the site is not navigated to. The error
'org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?'
is shown in the console logs.
So is this issue to do with how I have set my feature files up to use the startBrowser, initBrowser and closeBrowser methods. Which are
defined in a seperate class 'BrowserInitTearDownStepDefinitions'?
All my feature files look like ..
Feature: Update a Computer in Database
-- left out details
#StartBrowser
Scenario: Start browser session
When I initialize driver
Then open browser
#MyTest4
Scenario Outline: Update a computer
-- left our details
Examples:
-- left out details
#CloseBrowser
Scenario: Close the browser
Then close browser
I have had a look at the other posts related to this message that reference the same error, but can't see a clear cut solution.
As the error would indicate I seem to be quitting the driver but then not reinitialising it for the next test. Although Im not sure why this
would be the case given that each feature file has the #StartBrowser and #CloseBrowser tags which should execute these methods. Below is my BrowserInitTearDownStepDefinitions class.
public class BrowserInitTearDownStepDefinitions {
//Initialises Chrome browser
#When("^I initialize driver$")
public void initializeDriver() {
System.out.println("initializeDriver runs");
System.setProperty("webdriver.chrome.driver","C:\\xxxx\\CucumberAutomationFramework\\src\\test\\java\\cucumberAutomationFramework\\resources\\chromedriver.exe");
WebDriverUtils.setDriver(new ChromeDriver());
}
//Opens Chrome browser and clicks in search input box
#Then("^open browser$")
public void openBrowser() {
System.out.println("Open Browser runs");
WebDriver driver = WebDriverUtils.getDriver();
driver.manage().window().maximize();
driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);
driver.manage().timeouts().setScriptTimeout(60, TimeUnit.SECONDS);
driver.get("https://computer-database.gatling.io/computers");
}
//Closes browser after all scenarios run and deletes cookies
#Then("^close browser$")
public void closeBrowser() {
System.out.println("Close Browser runs");
WebDriver driver = WebDriverUtils.getDriver();
driver.manage().deleteAllCookies();
driver.quit();
driver =null;
}
}
I create a new instance of the webdriver within my stepDefs file with ..
WebDriver driver = WebDriverUtils.getDriver()
The webdriver utils class code is ..
package cucumberAutomationFramework.utilityClasses;
import org.openqa.selenium.WebDriver;
public class WebDriverUtils {
private static WebDriver driver;
public static void setDriver(WebDriver webDdriver) {
if (driver == null) {
driver = webDdriver;
}
}
public static WebDriver getDriver() {
if (driver == null) {
throw new AssertionError("Driver is null. Initialize driver before calling this method.");
}
return driver;
}
}
Any advice would be much appreciated. Thanks.
I am able to run the selenium test in our project without using System.setProperty. Not sure how it works, we have set the environment Path variable with value "C:\Akash\Drivers" where all the drivers are stored. Can anyone explain how/ this works without setting up chrome path?
public class SeleniumTest {
public static void main(String[] args) throws MalformedURLException {
// TODO Auto-generated method stub
localSettings();
}
public static void localSettings() {
// System.setProperty("webdriver.chrome.driver", "C:\\Akash\\Drivers\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com");
}
}
Please Refer official explanation given Seleniumhq & Chrome,
How it retrieves and Work with Environment Variables :
WebDriver works with Chrome through the chromedriver binary. You need to have both chromedriver and a version of chrome browser installed. chromedriver needs to be placed somewhere on your system’s path in order for WebDriver to automatically discover it. The Chrome browser itself is discovered by chromedriver in the default installation path. These both can be overridden by environment variables.
Provided by Seleniumhq, Blog Link : Click Here
Chrome Driver Setup Provisions:
Provided by Chrome, Blog Link : Click Here
I am facing an weird issue. I have a selenium suite to execute on multiple browsers. It works fine of chrome and Firefox. But in case of IE, the web page under test gets shrunk (web page resize) making elements hidden. Hence facing NoSuchElementException.
I have already tried executing on full screen. No help.
Please help in solving this issue.
Thanks,
Praveen
Don't know the exact reason for that, however, suggested workaround would be to implement pre-execution method for your test which would take care of all your browser different configurations. For example, if you are using Java with Selenium and JUnit5, it might be:
#BeforeEach
void beforeTestExecution() {
DesiredCapabilities desiredCapabilities = DesiredCapabilities.internetExplorer();
desiredCapabilities.setCapability(
CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
driver = new InternetExplorerDriver(desiredCapabilities);
// Navigate to URL
driver.get("http://www.yoursite.com");
// Maximize your website window before test.
driver.manage().window().maximize();
}
Or:
#BeforeEach
void configBrowser() {
DesiredCapabilities desiredCapabilities = DesiredCapabilities.internetExplorer();
desiredCapabilities.setCapability(
CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
driver = new InternetExplorerDriver(desiredCapabilities);
// Start Internet Explorer maximized.
driver.manage().window().maximize();
}
I am writing a simple program in Eclipse using JUnit annotation.
diver.close() is not closing my Firefox browser after the tests. It works fine with Chrome. Code snippet is here.
public class FireFox1 {
WebDriver driver;
#Before
public void setUp() {
driver= new FirefoxDriver();
driver.get("http://book.theautomatedtester.co.uk/chapter4");
}
#After
public void tearDown() {
driver.close();
}
#Test
public void testExamples() {
WebElement element= driver.findElement(By.id("nextBid"));
element.sendKeys("100");
}
}
sometimes while on repeated usages,we'll facing problems with driver.close().
Anyways driver.quit() will rectify your problem.
Generally driver.close() closes the browser(the instance of driver is still intact) and driver.quit() is to kill the webdriver instance. As anyhow you are using here for only one page,then you can go with driver.quit().
Thank you.
Better use driver.quit() method. It closes the browser, but due to some unknown issues it throws NullPointerException. Just catch it..
try{
driver.quit();
}catch (Exception e){
System.out.println("Nothing to do with it");
}
Assuming you have started 5 browsers(classes) parallely using grid:
driver.close - Used for close the current browser( where execution going on)
driver.quit - Used for close all the browsers started by the current execution.
You can use any one of this..
May be browser compatiblity issue, try to downgrade the FF let we see...
Use latest GeckoDriver.exe (17) with Latest FireFox (54.0);
It works fine for me. I had the same problem before.
This problem that you are facing is completely a compatibility problem between driver & Browser version.
driver.close(); should have work without problem if you use above versions. Let me know if it works.
This is what the problem in Firefox driver.close() works in Firefox only with internet connection but in case of Chrome it works without internet connection.
I am using simple selenium example using Web driver classes, but the IE web driver class working fine, but the Firefox is not responding not opening browser and not throwing any error in console.
code is here
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class GoogleSearchFF {
public static void main(String args[]){
WebDriver driver=new FirefoxDriver();
System.out.println("Loading Google search page");
driver.get("http://www.google.com");
System.out.println("Google search page loaded fine");
}
}
selenium jar files added to classpath..
\selenium-java-2.13.0\selenium-2.13.0\selenium-java-2.13.0.jar
\selenium-java-client-driver-1.0.1\selenium-java-client-driver.jar
\Selenium Latest\selenium-server-standalone-2.13.0.jar
any jar is missing?
The code works for IE by setting proeprty INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS = true
Downgrade the Firefox version to 8 as Selenium 2.13.0 supports Firefox versions upto 8 only.
For reference check this log.
Instead of downgrading Firefox to 8,
You need to download the geckodriver.exe and set the System.property() by
System.setProperty("webdriver.gecko.driver", "pathTogeckodriver");
before calling WebDriver driver = new FirefoxDriver();