selenium firefox path setting problems - selenium

no matter what I do selenium doesn't accept my firefox path in the console where I launch it from. Keep getting the same error.
I also set the path as an environment variable in win 7 64.
I'm pretty much a virgin when it comes to selenium. Trying to run my first JUNIT test.
Here is the message from selenium.
21:46:43.481 INFO - Command request: getNewBrowserSession[*chrome, http://compendiumdev.co.uk/, ] on session null
21:46:43.497 INFO - creating new remote session
21:46:43.544 INFO - Got result: Failed to start new browser session: java.lang.RuntimeException: java.lang.RuntimeException: Firefox could not be found in the path!
Please add the directory containing ''firefox.exe'' to your PATH environment
variable, or explicitly specify a path to Firefox like this:
*firefox c:\blah\firefox.exe on session null
Below is my java code
package com.eviltester.seleniumtutorials;
import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class MyFirstSeleniumTests {
Selenium selenium=null;
#Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*chrome",
http://compendiumdev.co.uk/");
selenium.start();
}
#Test
public void testExported() throws Exception {
selenium.open("/selenium/search.php");
selenium.type("q", "Selenium-RC");
selenium.click("name=btnG");
}
#After
public void tearDown() throws Exception {
selenium.stop();
}
}
Thank you for the help.

Related

Exception in thread Unresolved compilation problems:

This is my script:
package sampleTests;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class AdminLogin {
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver = new FirefoxDriver(); //Launches Firefox Browser with blank url
driver.close();
}
}
When I run the script, am getting below error, I tried to add the java lib in Class path instead of Module path, still the issue not resolved, someone please help;
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
WebDriver cannot be resolved to a type FirefoxDriver cannot be resolved to a type at sampleTests.AdminLogin.main(AdminLogin.java:10)
You have to set the path of the Geckodriver (the executable that is used for Firefox tests using Selenium).
Search for Geckodriver in Google.
Download the executable as per your system (Win/Mac/Linux)
Set the path of the executable in your tests as given below -
package sampleTests;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class AdminLogin {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.gecko.driver",Path_of_Firefox_Driver");
// example for Windows
System.setProperty("webdriver.gecko.driver",D:\\GeckoDriver\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://testautomationu.applitools.com/");
driver.quit();
}
}

org.openqa.selenium.InvalidArgumentException: Invalid argument

I'm new to this site and I would like to request your help and expert opinion on this issue.
I'm currently trying to run a simple code using Netbeans and Selenium, but everytime I run the code I get the error "Exception in thread "main" org.openqa.selenium.InvalidArgumentException: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir"
This is the code I'm trying to run, something weird is that I can successfully run the same code on a different computer.
package selenium.test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class SeleniumTest {
private static WebDriver driver = null;
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver",
"C:\\Users\\Kevin\\Documents\\Selenium\\Driver\\chromedriver.exe");
driver = new ChromeDriver();
driver.get ("https:\\www.google.com");
}
}
Chrome Version: 77.0.3865.90
ChromeDriver Version: 77.0.3865.40
Netbeans: 8.2
Thank you very much for your help
Use ChromeOptions. You can specify a directory that's not your user's directory:
ChromeOptions co = new ChromeOptions();
co.addArguments("user-data-dir=C:\\Some\\valid\\data dir\\");

selenium grid connction with autoit not working?

selenium grid connection with auto it not working ?
#daluudaluu/PartialSeleniumGridIntegrationWithAutoItExample.java
Last active a year ago
Embed
Download ZIP
Code Revisions 2 Forks 1
Partial Selenium Grid integration support with tools like AutoIt, Sikuli, etc.
Raw
PartialSeleniumGridIntegrationWithAutoItExample.java
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.*;
import org.openqa.selenium.remote.*;
import java.net.URL;
public class DemoTest {
public WebDriver driver;
public DesiredCapabilities capabilities;
#Before
public void setUp() throws Exception {
capabilities = DesiredCapabilities.firefox();
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub" ), capabilities);
}
#After
public void tearDown() throws Exception {
driver.quit();
}
#Test
public void test() throws Exception {
// Use RemoteWebDriver, grab actual node host info
driver.get("http://www.google.com");
String sessionId = ((RemoteWebDriver) driver).getSessionId().toString();
//grid info extractor from: https://gist.github.com/krmahadevan/1766772
String nodeHost = GridInfoExtracter.getHostNameAndPort("localhost", 4444, sessionId)[0];
System.out.println("Extracted hostname: "+nodeHost);
// Now use node host info to handle running AutoIt on that specific node, assuming all needed files deployed to all nodes
// Case 1 - PSExec.exe from Windows host (that is executing this Selenium code) to Selenium node that is Windows host
//String psexecCmd = "C:\\LocalMachinePathTo\\psexec.exe \\\\%s -u %s -p %s -i C:\\GridNodeMachinePathTo\\autoitCompiledScript.exe";
//Process p = Runtime.getRuntime().exec(String.format(psexecCmd,nodeHost,"jdoe","hisPassword"));
//p.waitFor();
// Case 2 - winexe from *nix host (that is executing this Selenium code) to Selenium node that is Windows host
// Example reference: http://secpod.org/blog/?p=661
//String winexeCmd = "/LocalMachinePathTo/winexe -U domainName/jdoe%hisPassword //"+nodeHost+" C:\\GridNodeMachinePathTo\\autoitCompiledScript.exe";
//Process p = Runtime.getRuntime().exec(winexeCmd);
//p.waitFor();
// Case 3 - have SSH installed on Windows-based Selenium nodes, now just connect to node host via SSH to run a command, i.e. execute AutoIt script binary
// no sample code given for Java, but maybe this gives you ideas on Java SSH connection:
// http://stackoverflow.com/questions/995944/ssh-library-for-java
// Case 4 - if you have implemented a custom web service (XML-RPC/SOAP/REST) for AutoIt that listens for requests/commands
// just connect to it via (Java) HTTP library to "http://"+nodeHost+"/someWebServicePath/someCommand" (via GET or POST)
// details not covered, this is just an example. Most people won't be taking this route due to customization & complexity in
// building the web service first
// Case 5 - using AutoItDriverServer that is also running on Selenium nodes
//DesiredCapabilities autoitCapabilities = new DesiredCapabilities();
//autoitCapabilities.setCapability("browserName", "AutoIt");
//WebDriver autoitDriver = new RemoteWebDriver(new URL("http://"+nodeHost+":4723/wd/hub"), autoitCapabilities);
//autoitDriver.findElement(By.id("133")).click();
//and whatever other AutoItX commands to call that you normally have in the AutoIt script that you compile into binary
//for more ideas on AutoIt commands issued as WebDriver commands with respect to Selenium integration, see:
//https://github.com/daluu/AutoItDriverServer/blob/master/sample-code/SeleniumIntegrationWithAutoItDriver.py
//or if you are old school, and want to do that same approach even with AutoItDriverServer,
// assuming you have first set AutoItScriptExecuteScriptAsCompiledBinary to True in autoit_options.cfg file before starting AutoItDriverServer:
//((JavascriptExecutor) autoitDriver).executeScript("C:\\GridNodeMachinePathTo\\autoitCompiledScript.exe");
// Case for Sikuli integration, using https://github.com/enix12enix/sikuli-remote-control
//RemoteScreen rs = new RemoteScreen(nodeHost);
//rs.setMinSimilarity(0.9);
//rs.click("D://test.png");
}
}

Running Seleniuem web driver 2.53.0 with Firefox 47.0

I have just started running test scripts using selenium web driver. I coded the following code as a start.
package myPackage;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class myTest {
public static void main(String[] args){
WebDriver driver = new FirefoxDriver();
driver.get("http://www.facebook.com");
driver.manage().window().maximize();
}
}
When I run it as Java application, It always shows the following error message.
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Just the browser opens, but the facebook page doesn't get opened.
What is the solution for this?

selenium - jUnit4

I am trying to run the below code but in vain.
Code is not compiling and giving error as "selenium cannot be resolved".
Can anyone look into the below code -
package com.example.tests;
import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.regex.Pattern;
public class prashantk {
#Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://book.theautomatedtester.co.uk/");
selenium.start();
}
#Test
public void testAuto_1() throws Exception {
selenium.open("/chapter2");
verifyEquals("Button with name", selenium.getValue("name=but2"));
verifyEquals("chocolate", selenium.getValue("xpath=(//input[#name='verifybutton'])[2]"));
selenium.click("link=Index");
selenium.waitForPageToLoad("60000");
verifyTrue(selenium.isTextPresent("Chapter4"));
}
#After
public void tearDown() throws Exception {
selenium.stop();
}
}
You have references to a field named selenium, but there is no such field defined.
Somewhere in your class, probably on a line just before the #Before, you want to add this field:
Selenium selenium;
Apparently from comments you also don't have the methods verifyEquals and verifyTrue referenced in your code. Those methods are defined in a base class SeleneseTestCase which your test should extend:
public class prashantk extends SeleneseTestCase {
Replace the below line in your code as shown below
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://book.theautomatedtester.co.uk/");
to
DefaultSelenium selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://book.theautomatedtester.co.uk/");
Looking at code gives an impression it was done in Selenium IDE first the exported to a tool like eclipse.
I really don't think 'verifyEquals' exist in WebDriver instead use JUnit assertions or Hamcrest assertions. Try to write your code from scratch in Java its a lot less hassle.