java.lang.IllegalStateException: Error configuring Firefox Browser in Selenium - webdriver

Java Version - 1.8
Eclipse Version - 2018-09 (4.9.0)
Selenium - 3.141
Firefox expandable file - v0.23.0
My code :
package testcases;
import org.openqa.selenium.firefox.FirefoxDriver;
public class TestBrowsers {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.gecko.driver", "C:\\Users\\adiwakar\\Documents\\Selenium Browser files");
FirefoxDriver driver = new FirefoxDriver();
driver.get("https://www.google.com/");
}
}
Errors:
Exception in thread "main" java.lang.IllegalStateException: The driver executable is a directory: C:\Users\adiwakar\Documents\Selenium Browser files
at com.google.common.base.Preconditions.checkState(Preconditions.java:585)
at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:148)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:141)
at org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:44)
at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:167)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:355)
at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:190)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:147)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:125)
at testcases.TestBrowsers.main(TestBrowsers.java:10)

It looks like you defined a path as a driver, you should define your driver executables path as a driver like following code :
System.setProperty("webdriver.gecko.driver", "C:\\Users\\adiwakar\\Documents\\yourDriver.exe");

Related

javafx error even though url is correct

Even though the path given is correct & image is displaying in scene builder, it is throwing error while running the application.
Executing C:\Users\433240\Documents\NetBeansProjects\UI\dist\run547088191\UI.jar using platform C:\Program Files (x86)\Java\jdk1.8.0_40\jre/bin/java
Device "Intel(R) G41 Express Chipset" (\\.\DISPLAY1) initialization failed :
WARNING: bad driver version detected, device disabled. Please update your driver to at least version 8.15.10.2302
null/Images/home.png
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Caused by: java.lang.IllegalArgumentException: Invalid URL or resource not found
at javafx.scene.image.Image.validateUrl(Image.java:1091)
... 23 more
Exception running application ui.Main
Java Result: 1
I had the same problem
Solution:
go to java controller class and write this code
private Image image;
#FXML
ImageView imageview; // type your imageview fixid
private void setImage(String url) {
try {
image = new Image(url);
imageview.setImage(image);
} catch (Exception e) {
System.out.println(e);
}
}

Error while running client code in EJB

Getting error while running client code in EJB:
Exception in thread "Main Thread" java.lang.NoClassDefFoundError:
weblogic/kernel/KernelStatus at
weblogic.jndi.Environment.(Environment.java:78) at
weblogic.jndi.WLInitialContextFactory.getInitialContext(WLInitialContextFactory.java:117)
at
javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
at
javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.init(InitialContext.java:223) at
javax.naming.InitialContext.(InitialContext.java:197) at
User.main(User.java:21)
I added wlfullclient.jar, server's Remote interface jar, also I saw article in which I saw to add wlclient.jar and weblogic.jar but then also got same error.
Help highly appreciated.
Client code:
import com.amdocs.Stateful.*;
import java.util.Hashtable;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class User
{
public static void main(String args[]){
Hashtable<String,String> ht = new Hashtable<String,String>();
ht.put(InitialContext.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");// you have to start from root location to search for JNDI tree
//JNDI registry tree is normally maintained as Binary tree, JNDi is normally binary tree which have root node at top
ht.put(InitialContext.PROVIDER_URL,"t3://localhost:7001"); // address of registry
try{
System.out.println("Hello");
InitialContext ic = new InitialContext(ht); // start searching wrt what we set in ht , it's constructor takes HashTable only
System.out.println("Hello2");
MyCartRemote ref=(MyCartRemote)ic.lookup("MyCartBeanJNDI#com.amdocs.Stateful.MyCartRemote");
ref.add("Hi");
ref.add("Jeetendra");
MyCartRemote ref1=(MyCartRemote)ic.lookup("MyCartBeanJNDI#com.amdocs.Stateful.MyCartRemote");
ref1.add("Hi");
ref1.add("Subhash");
ref1.add("Ghai");
System.out.println("Object 1 data: "+ref.show());
System.out.println("Object 2 data: "+ref1.show());
}
catch (NamingException e){ e.printStackTrace(); }
}
}
Try removing WebLogic System Libraries from the Bootstrap Entries section. It worked for me when i got the same error.

JavaFx in headless mode

Is it possible to run JavaFx in headless mode(in Java 7)? It is being used to generate images on the server but is asking for an X-Server. Does there exist something like java.awt.headless in JavaFx ?(I can't use Xvfb )
Here is how I solved this problem for server-side image geneartion on Ubuntu linux environment with jetty application server. It uses xvfb but only as a "library" - without any additional special actions on server:
apt-get install xvfb
// then on application server start:
export DISPLAY=":99"
start-stop-daemon --start --background --user jetty --exec "/usr/bin/sudo" -- -u jetty /usr/bin/Xvfb :99 -screen 0 1024x768x24
You can see the details of my server-side image generation solution in this SO question.
This is a kind of problem which I encountered while capturing images in Mac OS.
I have solved this issue by using
static {
System.setProperty("java.awt.headless", "false");
}
See for reference : Headless environment error in java.awt.Robot class with MAC OS
Answer by Shreyas Dave didn't work for me anymore. Though I don't know why, here is what I did:
public static void main(String[] args) {
// to avoid
// [JRSAppKitAWT markAppIsDaemon]: Process manager already initialized: can't fully enable headless mode.
System.setProperty("javafx.macosx.embedded", "true");
java.awt.Toolkit.getDefaultToolkit();
// end
launch(args);
}
This was also pointed out here: JavaFX screencapture headless exception on OSX
If you have the source code of the JavaFX application you could also try to use TestFX run the application in a headless mode, to control it and to make screenshots. To run your TestFX application in headless mode you have to start it with the following JVM parameters (to enable Monocle):
-Dtestfx.robot=glass -Dglass.platform=Monocle -Dmonocle.platform=Headless -Dprism.order=sw
Moreover you might need to install Monocle first. See Headless testing with JavaFx and TestFx for more information.
I have an application that can be used interactively (displaying JavaFx dialogs) but also must be able to run non-interactive on a server without display.
Even though no GUI element is used in non-interactive mode, we got
Caused by: java.lang.UnsupportedOperationException: Unable to open DISPLAY
at com.sun.glass.ui.gtk.GtkApplication.<init>(GtkApplication.java:68)
This happens as soon as a class derived from javafx.application.Application is instantiated, which you normally do with your main class.
Here is the way I solved the problem:
I created an additional class GuiAppExecution:
import java.util.List;
import javafx.application.Application;
import javafx.stage.Stage;
/**
* JavaFx launch class for {#link AppExecution}.
*/
public class GuiAppExecution extends Application {
#Override
public void start(Stage stage) throws Exception {
List<String> parameters = getParameters().getRaw();
AppExecution appExecution = new AppExecution();
appExecution.launch(parameters);
}
/**
* Launches the {#link AppExecution} as JavaFx {#link Application}.
*
* #param parameters program parameters
*/
public void launchGui(String[] parameters) {
launch(parameters);
}
}
In the main class AppExecution I created a method
public void launch(List<String> parameters) {
which parses the parameters and launches the application for both interactive and non-interactive execution.
The main method looks like this:
public static void main(String[] parameters) {
List<String> parameterList = Arrays.asList(parameters);
if (parameterList.stream().anyMatch(p -> p.equalsIgnoreCase(BATCH_PARAMETER))) {
AppExecution appExecution = new AppExecution();
appExecution.launch(parameterList);
}
else {
GuiAppExecution guiAppExecution = new GuiAppExecution();
guiAppExecution.launchGui(parameters);
}
}
with
private static final String BATCH_PARAMETER = "-batch";
as the program option that request the non-interactive execution.
Since GuiAppExecution (which is derived from javafx.application.Application) is not instantiated for non-interactive execution, the JavaFx environment is not started.

UnsatisfiedLinkError with javafx

I am trying do learn javafx. I have a very simple program to print "Hello World" once in the main method (as a test) and once in the Application. The code looks like this:
import javafx.stage.*;
import javafx.application.*;
public class HelloApp extends Application
{
public static void main(String[] args)
{
System.out.println("Hello World");
launch(args);
}
public void start(Stage stage)
{
System.out.println("Hello World");
}
}
this gives me the following output. Note that it prints the first "Hello World", but not the second.
--------------------Configuration: javafx trials - JDK version 1.6.0_07 <Default> - <Default>--------------------
Hello World
Exception in thread "main" java.lang.RuntimeException: java.lang.UnsatisfiedLinkError: Can't load library: C:\Documents and Settings\apcs.LGSUHSD\My Documents\JCreator LE\MyProjects\bin\glass.dll
at com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:281)
at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:124)
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:163)
at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47)
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.UnsatisfiedLinkError: Can't load library: C:\Documents and Settings\apcs.LGSUHSD\My Documents\JCreator LE\MyProjects\bin\glass.dll
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1650)
at java.lang.Runtime.load0(Runtime.java:770)
at java.lang.System.load(System.java:1005)
at com.sun.glass.utils.NativeLibLoader.loadLibraryFullPath(NativeLibLoader.java:200)
at com.sun.glass.utils.NativeLibLoader.loadLibraryInternal(NativeLibLoader.java:88)
at com.sun.glass.utils.NativeLibLoader.loadLibrary(NativeLibLoader.java:31)
at com.sun.glass.ui.Application.loadNativeLibrary(Application.java:73)
at com.sun.glass.ui.Application.loadNativeLibrary(Application.java:80)
at com.sun.glass.ui.win.WinApplication$1.run(WinApplication.java:36)
at com.sun.glass.ui.win.WinApplication$1.run(WinApplication.java:33)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.glass.ui.win.WinApplication.<clinit>(WinApplication.java:33)
at com.sun.glass.ui.win.WinPlatformFactory.createApplication(WinPlatformFactory.java:20)
at com.sun.glass.ui.win.WinPlatformFactory.createApplication(WinPlatformFactory.java:17)
at com.sun.glass.ui.Application.Run(Application.java:103)
at com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:271)
... 5 more
Process completed.
I have no Idea why this is happening. I have the jar file for javafx in the project. Can someone please explain why this is happening and what I can do about it?
if you are using eclipse add C:\Program Files\Oracle\JavaFX Runtime\lib\jfxrt.jar as external jar and rebuild project.

Unable to connect to host 127.0.0.1 on port 7055

I am a newbie with webdriver and need some help..
I am using Selenium 2.2.0 with FF v7.0.1 on Windows XP
I've managed to record and play back a java script successfully in IE but whenever I try and execute the same script in FF, I get the following error message:
Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms
I've read at numbe of places that if I downgrade the firefox version to 3.6 script will work fine however I am not to keen on downgrading. Can someone please tell me what I am doing wrong?
package hisScripts;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
public class WebdriverTest_1 {
private WebDriver driver;
private String baseUrl;
private StringBuffer verificationErrors = new StringBuffer();
#Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
//driver=new InternetExplorerDriver();
baseUrl = "https://**********/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#Test
public void testUntitled() throws Exception {
driver.get(baseUrl + "/");
driver.findElement(By.xpath("//a[contains(text(),'my profile')]")).click();
driver.findElement(By.xpath("//a[contains(text(),'about the service')]")).click();
driver.findElement(By.xpath("//a[contains(text(),'contact us')]")).click();
driver.findElement(By.xpath("//a[contains(text(),'help')]")).click();
driver.findElement(By.xpath("//a[contains(text(),'home')]")).click();
driver.findElement(By.xpath("//a[contains(text(),'logout')]")).click();
}
#After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
}
The selenium version you are using is extremely old. I don't think firefox 10 is supported in v2.2. The latest is 2.20.
Take a look at change log here. From the notes here native events in firefox 10 were supported starting from v2.19.0 that means you would need 2.19 or higher to support firefox 10.
This problem is due to the compatibility of fire fox version and the selenium jar file version.Use the latest selenium jar files.that can fix the problem.

Resources