Selenium Server not starting - selenium

package com.memoir.client.widgets.memogen;
import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.thoughtworks.selenium.DefaultSelenium;
#SuppressWarnings("deprecation")
public class TestHomepage extends SeleneseTestCase {
#Override
#Before
public void setUp() throws Exception {
//selenium = new DefaultSelenium("localhost", 4444, "*firefox", "https://64.79.128.233/staging/");
selenium = new DefaultSelenium("localhost", 4444, "*firefox /usr/bin/firefox", "https://64.79.128.233/staging/");
selenium.start();
}
#Test
public void testTesting4() throws Exception {
selenium.setSpeed("2000");
selenium.windowMaximize();
//selenium.open("/memosyn/");
selenium.open("/staging/");
selenium.waitForPageToLoad("60000");
//Checking for page layout in the beginning of the web page
assertEquals("1", selenium.getElementIndex("//*[#id='isc_G']"));
assertEquals("Please contact support#systems.com for questions or comments.", selenium.getText("id=contactText"));
//assertEquals("MemoWeb V3.3.5963M", selenium.getText("//*[#id='isc_WidgetCanvas_1_widget']/div/table/tbody/tr/td[2]"));
assertEquals("14", selenium.getElementHeight("scLocator=//VLayout[ID=\"loginBox\"]/"));
assertEquals("447", selenium.getElementWidth("scLocator=//VLayout[ID=\"loginBox\"]/"));
assertEquals("35", selenium.getElementHeight("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=email]/title"));
assertEquals("207", selenium.getElementWidth("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=email]/title"));
assertEquals("35", selenium.getElementHeight("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=password]/title"));
assertEquals("207", selenium.getElementWidth("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=password]/title"));
assertEquals("35", selenium.getElementHeight("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=rememberMe]/textbox"));
assertEquals("203", selenium.getElementWidth("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=rememberMe]/textbox"));
assertEquals("22", selenium.getElementHeight("scLocator=//Button[ID=\"submitButton\"]/"));
assertEquals("100", selenium.getElementWidth("scLocator=//Button[ID=\"submitButton\"]/"));
assertEquals("MemoWeb", selenium.getTitle());
assertEquals("Email :", selenium.getText("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=email||title=Email]/title"));
assertEquals("Password :", selenium.getText("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=password||title=Password]/title"));
assertEquals("Remember me on this computer", selenium.getText("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=rememberMe||title=Remember%20me%20on%20this%20computer]/textbox"));
}
#Override
#After
public void tearDown() throws Exception {
selenium.stop();
}
}
This is the code and when I run this by starting the selenium server i get this error.
What could be the reason for the error? Is it that my firefox profile is not set properly?
java.lang.RuntimeException: Could not start Selenium session: Failed to start new browser session: org.openqa.selenium.server.browserlaunchers.InvalidBrowserExecutableException: The specified path to the browser executable is invalid.
at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:109)
at com.memoir.client.widgets.memogen.TestHomepage.setUp(TestHomepage.java:16)
at junit.framework.TestCase.runBare(TestCase.java:132)
at com.thoughtworks.selenium.SeleneseTestCase.runBare(SeleneseTestCase.java:230)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: com.thoughtworks.selenium.SeleniumException: Failed to start new browser session: org.openqa.selenium.server.browserlaunchers.InvalidBrowserExecutableException: The specified path to the browser executable is invalid.
at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:112)
at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:106)
at com.thoughtworks.selenium.HttpCommandProcessor.getString(HttpCommandProcessor.java:275)
at com.thoughtworks.selenium.HttpCommandProcessor.start(HttpCommandProcessor.java:237)
at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:100)
... 16 more
Can anyone help me fix this?
I get those errors and I have no clue please help me .

Selenium RC works on Eclipse with versions less that 12 . Can you pls check which version you are using

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();
}
}

ChromeDriver Selenium exception

Im using Mac laptop, I got this from youtube for mac tutorial, but its working for other students
Forgive me I am new to selenium
Not sure if Im missing something
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Main {
public static void main(String [] args) {
System.setProperty("webdriver.chrome.driver","/Users/c054148/Downloads/chromedriver");
WebDriver obj = new ChromeDriver();
obj.get("https://www.google.com");
}
} Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap
at org.openqa.selenium.remote.service.DriverService$Builder.(DriverService.java:259)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.(ChromeDriverService.java:101)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:94)
at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:123)
at Main.main(Main.java:8)
Caused by: java.lang.ClassNotFoundException: com.google.common.collect.ImmutableMap
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 5 more
Seems you have missed the extension of the ChromeDriver. It should be chromedriver.exe
System.setProperty("webdriver.chrome.driver","/Users/c054148/Downloads/chromedriver.exe");

selenium firefox path setting problems

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.

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.

Element is not clickable at point using chrome driver

I am trying to download payslip as PDF from greytip web portal using chrome driver.i am trying to click on link salary by using "driver.findElement(By.linkText("Salary")).click();".But i am unable to click the link and failed with following exception.
Error
org.openqa.selenium.WebDriverException: Element is not clickable at point (198, 139). Other element would receive the click: ... (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 37 milliseconds
And also when ever i ran the script chrome open one extra tab for bit torrent.so here when i ran the program one tab is opened for "https://psdpl.greytip.in" and another tab is opened for bittorrent.How can i handle not to open another bittorrent tab when i ran the program.
Here i am attaching the code and screen shots.enter image description here
Code
package com.webdriver.tests;
import static org.junit.Assert.*;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class PaySlipPDF {
private WebDriver driver;
private String baseUrl;
private StringBuffer verificationErrors = new StringBuffer();
#Before
public void setUp() throws Exception {
System.setProperty("webdriver.chrome.driver", "C:\\soleti\\D-Drive\\Selenium\\chromedriver\\chromedriver.exe");
driver = new ChromeDriver();
baseUrl = "https://psdpl.greytip.in/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#Test
public void testPayslip() throws Exception {
driver.get(baseUrl + "/login.do");
driver.findElement(By.id("j_username")).clear();
driver.findElement(By.id("j_username")).sendKeys("101786");
driver.findElement(By.id("j_password")).clear();
driver.findElement(By.id("j_password")).sendKeys("password");
driver.findElement(By.id("login-button")).click();
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
//driver.findElement(By.xpath("//*[#id='home-page']/div[1]/div[1]/ul/li[2]/a")).click();
WebElement elementToClick = driver.findElement(By.xpath("//*[#id='home-page']/div[1]/div[1]/ul/li[2]/a"));
System.out.println(elementToClick);
// Scroll the browser to the element's Y position
((JavascriptExecutor) driver).executeScript("window.scrollTo(0,"+elementToClick.getLocation().y+")");
// Click the element
elementToClick.click();
//driver.findElement(By.linkText("Salary")).click();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.linkText("View Payslips")).click();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
new Select(driver.findElement(By.id("payroll"))).selectByVisibleText("Mar 2012");
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.findElement(By.className("btn btn-gts-print")).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;
}
}
}
It is the BitTorrent toolbar that is causing the issue. It is launched into Chrome by an extension. Either uninstall it completely, or force Selenium to tell Chrome to disable all extensions. This can be done using the ChromeOptions class:
http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/chrome/ChromeOptions.html
Use the addArgument method and give it this arguement, which tells Chrome to disable all user extensions:
--disable-extensions
Check the browser settings and see if the default homepage has been changed by the bit torrent toolbar that is installed. If not needed, try to uninstall the bitTorrent toolbar from the browser and rerun your selenium program. Hope this helps.
This problem is specificaly related to chrome installed on your system..Uninstall the google chrome and re-install it..That will fix your problem..:)