New to Selenium - cannot access RemoteWebDriver error - selenium

I'm new to Selenium and I have tried to setup my first Selenium test using IntelliJ and Selenium 2. I have followed the tutorials on the official Selenium site but I get this error:
cannot access org.openqa.selenium.remote.RemoteWebDriver
class file for org.openqa.selenium.remote.RemoteWebDriver not found
This is the tutorial I am using - http://seleniumhq.org/docs/03_webdriver.html#chapter03-reference
This is the location for the Maven setup I followed - http://seleniumhq.org/docs/appendix_installing_java_driver_Sel20_via_maven.html#importing-maven-into-intellij-reference
Here is the code:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
public class MyAppHomePageTest {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
}
}
The error occurs when I try to create a FirefoxDriver instance. Do I need to have the Selenium server as I thought this is no longer required.
I have tried the same in Eclipse and received the same error.
Thank you

You should use this Maven dependency :
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.1.0</version>
</dependency>
According to this picture, you don't need a selenium-server dependency:
source : http://seleniumhq.org/download/maven.html

Related

Unable to run selenium webdriver scripts even after all the jars installed

I am unable to run selenium webdriver scripts on pc. I have all the necessary jar files and java installed on my pc but still I am getting just too many errors.I have attached the build path and errors in links below.
Here is the code:-
package Webdriver;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class firstscript {
public static void main(String args[]) {
System.setProperty("webdriver.chrome.driver","C:\\Users\\gkuma218\\Downloads");
WebDriver driver=new ChromeDriver();
String baseurl="https://stage-portal.uhcglobal.com/testMyUHC/generate-open-token.html";
driver.get(baseurl);
driver.findElement(By.id("txteeid")).sendKeys("00000907777");
driver.findElement(By.id("txtdob")).sendKeys("19920828");
driver.findElement(By.id("txtfirstname")).sendKeys("Sanette");
driver.findElement(By.id("txtlastname")).sendKeys("ABATE");
driver.findElement(By.id("txtgroupid")).sendKeys("0742631");
driver.findElement(By.id("btnSubmit")).click();
}
}
Here are the errors:-
https://i.stack.imgur.com/m2euR.png
Here is the build path:-
https://i.stack.imgur.com/l5692.png
Possibly a classic case of Cyclic redundancy.
Solution:
Either you rename the project name as seleniumTests and module name as webdriverTests
Or you may like to create a new project with a unique name excluding the keywords selenium and webdriver.

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\\");

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

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

Extent Report no generating html

Hi I am trying to create report through Extent Report; the code gives no error and runs successfully but there is no html report generated. Can anyone please help below is my code -
package ca.automation.com;
import org.testng.annotations.Test;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import org.testng.annotations.BeforeTest;
import org.junit.Assert;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.AfterClass;
public class ExtentReport {
WebDriver driver;
ExtentReports extent;
ExtentTest test;
#BeforeTest
public void startReport(){
extent = new ExtentReports("C:\\Report.html", true);
}
#Test
public void installapp() {
test = extent.startTest("installapp");
System.setProperty("webdriver.ie.driver", "C:\\Anuj\\Downloads\\IEDriverServer_Win32_2.46.0\\IEDriverServer.exe");
driver = new InternetExplorerDriver();
driver.manage().window().maximize();
driver.get("https://www.tripadvisor.com/");
String Title = driver.getTitle();
Assert.assertTrue(Title.contains("Trip"));
extent.endTest(test);
}
}
Append extent.flush(); at the end of the test method to write all the test logs to the report file.
Check the documentation: http://extentreports.relevantcodes.com/java/#start-end-tests`
I think extent.flush(); is missing at the end.
the flush() and the close() needs to be called for the extent object to write the changes to the file. Call to close() must be done just before end of the Test as it closes the output stream
Call flush() in #AfterMethod method and close() in #AfterSuite method
#AfterMethod
public void afterMethod() {
extent.flush();
}
#AfterSuite
public void afterSuiteMethod() {
extent.close();
}
References :- ExtentReports Examples for Java
Here you go, just copy paste the working code in your project.
import org.testng.annotations.Test;
import com.dell.patientregister.mobilewallet.test.PatientRegister_SmokeTest;
import com.relevantcodes.extentreports.ExtentReports;
import org.testng.annotations.BeforeTest;
import org.junit.Assert;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class ExtentReport {
WebDriver driver;
ExtentReports extent;
#Test
public void installapp() {
ExtentReports extent = ExtentReports.get(ExtentReport.class);
extent.init("myreport.html", true);
extent.startTest(" Install App");
System.setProperty("webdriver.ie.driver", "C:\\Anuj\\Downloads\\IEDriverServer_Win32_2.46.0\\IEDriverServer.exe");
driver = new InternetExplorerDriver();
driver.manage().window().maximize();
driver.get("https://www.tripadvisor.com/");
String Title = driver.getTitle();
Assert.assertTrue(Title.contains("Trip"));
extent.endTest();
}
}
Please try this:
import org.testng.annotations.Test;
import com.dell.patientregister.mobilewallet.test.PatientRegister_SmokeTest;
import com.relevantcodes.extentreports.ExtentReports;
import org.testng.annotations.BeforeTest;
import org.junit.Assert;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class ExtentReport {
WebDriver driver;
ExtentReports extent;
#Test
public void installapp() {
ExtentReports extent = ExtentReports.get(ExtentReport.class);
extent.init("myreport.html", true);
test = extent.startTest(" Install App");
System.setProperty("webdriver.ie.driver","C:\\Anuj\\Downloads\\IEDriverServer_Win32_2.46.0\\IEDriverServer.exe");
driver = new InternetExplorerDriver();
driver.manage().window().maximize();
driver.get("https://www.tripadvisor.com/");
String Title = driver.getTitle();
Assert.assertTrue(Title.contains("Trip"));
test.Log(LogStatus.Pass, "Login Successful");
extent.endTest(test);
extent.flush();
extent.close();
}
}
Add extent.flush() at the end.
Please check if all the configurations are executed.i.e. your #BeforeClass,#AfterClass etc...
Sometimes they are skipped and so the extent.html is not generated.
So add the following tag "alwaysRun=true" with the testng annotation
e.g.#AfterMethod(alwaysRun = true)
It works :)
I got this error in testng project even though extent.flush() was added in code. The reason for not generating error was during execution exent.flush() line was not executed due to one of failed assertion. After removing that assertion script was working fine and file got generated as usual.
I had the same problem in generating Extent reports. The following solution worked for me.
Please add these commands at the end:
extent.EndTest(test);
extent.Flush();
Make sure you add this version from NuGet Packages - ExtentReports 2.41.0
If it is not working even after adding extent.flush(), Try by adding below dependencies in pom.xml
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.8.3</version>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.8.11.1</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.23</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver</artifactId>
<version>3.0.4</version>
</dependency>
In your test, you are not logging anything in report. If nothing is logged, no report would generate. As given below, try logging something in report. Also as per status of assertion, you can log PASS/FAIL in extentreport
test.log(LogStatus.INFO, "Test Started");
test.log(LogStatus.ERROR, "Test FAILED");
Adding bson-xxx.jar solved my same issue. Can try it out.

Selenium remote WebDriver issue

I am trying to do parallel execution using Selenium in my machine. I have configured hub and node successfully. But in my code, I am getting an error at remote web driver initialization.
My code:
package com.selenium.gautham;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.Test;
public class test {
#Test
public static void sample()
{
DesiredCapabilities cap =DesiredCapabilities.internetExplorer();
cap.setBrowserName("ie");
cap.setPlatform(Platform.WINDOWS);
RemoteWebDriver driver =RemoteWebDriver(new URL("http://localhost:4444/wb/hub"),cap);
driver.get(url);
}}
I'm getting this error:
The constructor RemoteWebDriver(URL, DesiredCapabilities) is undefined
Where did I do wrong?
Screenshot of Code
In your imports (before the start of the class), i haven't seen an import for the URL Class. I believe you are trying to use the below constructor of RemoteWebDriver Class.
RemoteWebDriver(java.net.URL remoteAddress, Capabilities desiredCapabilities)
If so, i would suggest you to first try replacing the below line
RemoteWebDriver driver =RemoteWebDriver(new URL("http://localhost:4444/wb/hub"),cap);
to the one below and see if its working fine.
RemoteWebDriver driver = RemoteWebDriver(java.net.URL("http://localhost:4444/wb/hub"), cap);
If you see the above alternative working then import
java.net.URL