Cannot execute testcase exported from selenium ide as java/junit4/remote control in eclipse ide - selenium

I am new to testing and i am trying to learn how to run recorded test cases in selenium ide in eclipse.
I recorded a testcase to search word selenium in the Google.
I exported it as java/junit4/remote control
Then i strated a new project in eclipse and add "java 4.12"and "selenium stand
alone server" external jar files.
I add the exporetd code to the project.
Then i started command prompt and executed selenium stand alone server.
Then i clicked run as junit in eclipse ide.
Firefox launched but an error is occured.
below is the code i executed:
package please;
import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import java.util.regex.Pattern;
public class please {
private Selenium selenium;
#Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "https://www.google.lk/");
selenium.start();
}
#Test
public void testPlease() throws Exception {
selenium.open("/?gfe_rd=cr&ei=10SKWaOqJ46AuATcuKPAAg");
selenium.type("id=lst-ib", "selenium");
selenium.type("id=lst-ib", "selenium");
assertEquals("selenium - Google Search", selenium.getTitle());
}
#After
public void tearDown() throws Exception {
selenium.stop();
}
}
This is what the result looks like

Recording tests via Selenium IDE is rarely a good option, mainly because many code snippets has to be refactored, lack of abstraction, modularity and so on (list is quite long actually). Looking at your code, I think that the problem is in the driver you are trying to use. According to this selenium mirror at Github. You should migrate to using WebDriver, instead of DefaultSelenium:
#deprecated The RC interface will be removed in Selenium 3.0. Please migrate to using WebDriver.
So, Selenium Interface and DefaultSelenium Class both belong to Selenium 1 and are deprecated. Selenium has advanced to Selenium 3 (WebDriver).
You will want to use the following classes as these are part of Selenium 3 (WebDriver). WebDriver is an interface used by various Selenium 3 drivers.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
Then you have various drivers that you can use. RemoteWebDriver / HtmlUnitDriver / FireFoxDriver / ChromeDriver / IEDriverServer etc. You will want to import the driver in your Java class.
Selenium selenium = new DefaultSelenium();
Becomes
WebDriver driver = new FireFoxDriver();

If your running the test using Selenium-Server try: (replace firefox with your browser version:
DesiredCapabilities capabillities= DesiredCapabilities.firefox();
capabillities.setCapability("platform", Platform.ANY);
capabillities.setCapability("name", "Testing Selenium-2 Remote WebDriver");
WebDriver driver = new RemoteWebDriver( new URL("http://localhost:4444/wd/hub"), capabillities);
driver.get("http://www.google.com");
assertEquals("Google", this.driver.getTitle());

Related

Web page stuck with loading bar while executing the automation script using Selenium?

I'm executing the automation script, in which I am facing loading bar for infinite time on the specific web page.
I have confirmed that issue is not from script side because earlier same scripts are executing fine.
I have applied the solutions as below.
Executing the script in other browsers
Increase wait time
Updated Chrome browser/chromedriver.exe
Currently I'm using below tools/version
Chrome Version: 89.0.4389.82
Chrome driver[Version:ChromeDriver89.0.4389.23]
Java [version: 11]
Selenium WebDriver
Can anyone please provide me the solutions?
Thanks in advance
Try changing the page load strategy to "eager":
This will make Selenium WebDriver to wait until the initial HTML document has been completely loaded and parsed, and discards loading of stylesheets, images and subframes.
When set to eager, Selenium WebDriver waits until DOMContentLoaded event fire is returned.
Example usage:
import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.chrome.ChromeDriver;
public class pageLoadStrategy {
public static void main(String[] args) {
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);
WebDriver driver = new ChromeDriver(chromeOptions);
try {
// Navigate to Url
driver.get("https://google.com");
} finally {
driver.quit();
}
}
}

Firefox browser not invoking from Selenium Webdriver version 3.4.0

So here is the issue:
Basically I'm trying to invoke Firefox browser with selenium.
package basics;
import org.openqa.selenium.WebDriver;
public class BrowserInvocation {
/**
* #param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe");
WebDriver driver=new FirefoxDriver();
// There is no import option displaying when mouse over FirefoxDriver such as **import org.openqa.selenium.firefox.FirefoxDriver;**
Console output:
Exception in thread "main" java.lang.Error: Unresolved compilation
problem:
FirefoxDriver cannot be resolved to a type at
basics.firefox.main(firefox.java:19)
I'm using latest versions of all software involve (as of May 15 2017) like firefox, java, eclipse and selenium. I have use 32 bit versions and 64 bit versions. tried removing everything and setup environment again but no luck.
I have tried invoking chrome in same environment with chrome driver and so far at least I can invoke the browser.

Firefox not opening the specified URL when I run my webdriver program

I am new to automation with selenium and trying to run a basic program to launch Firefox and open Google.com. But I get Firefox launched with "about:blank&utm_content=firstrun" Please help. Am on Windows 10 and Firefox version is: 48.0 (latest). I have the latest Selenium drivers and JRE versions too.
Here is my code:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class GoogleTest {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("http://google.com");
}
}

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 Web Driver firefox not responding

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