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.
Related
I have defined the following acceptance test scenario using selenium webdriver and junit which runs perfectly fine when executing the test with junit:
import org.junit.Test;
import org.junit.Before;
import org.junit.After;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import java.util.*;
public class SuccessfulLogin {
private WebDriver driver;
private Map<String, Object> vars;
JavascriptExecutor js;
#Before
public void setUp() {
System.setProperty("webdriver.chrome.driver", "C:\\drivers\\chromedriver.exe");
driver = new ChromeDriver();
js = (JavascriptExecutor) driver;
vars = new HashMap<String, Object>();
}
#After
public void tearDown() {
driver.quit();
}
#Test
public void firsttest() {
driver.get("http://localhost:9000/friendsify/login");
driver.manage().window().setSize(new Dimension(2576, 1408));
driver.findElement(By.name("username")).click();
driver.findElement(By.name("username")).sendKeys("max#mustermann.de");
driver.findElement(By.name("password")).click();
driver.findElement(By.name("password")).sendKeys("password");
driver.findElement(By.name("password")).sendKeys(Keys.ENTER);
driver.findElement(By.linkText("Friends")).click();
driver.close();
}
}
What is the proper way to make use of this test for testing the performance with JMeter?
First of all, are you aware of WebDriver Sampler plugin? Theoretically it can make your life easier.
Compile your test as .jar file
Put it under "lib/junit" path of your JMeter installation
Put all it's dependencies like selenium java library to "lib" folder of your JMeter installation
Restart JMeter to pick up the .jar
Your test class and method should be visible in JUnit Request sampler
More information: How to Use JUnit With JMeter
Be aware that browsers are very resource intensive, i.e. Firefox 96 requires 1 CPU core and 2 GB of RAM so you might need a powerful machine to conduct the load tests. So maybe it worth considering using HTTP Request samplers for load testing your application.
I am using Selenium to automate the CEF application. I am successfully able to perform operations like click etc. But not able to take the screenshot using Selenium driver. As it is very much required feature for automation. How can I do this?
I'm using the following:
CEF application - sample application provided by CEF
selenium jar - selenium-server-standalone-3.0.1
cef_binary_3.2924.1564.g0ba0378_windows64_client
chromedriver
Find the below code:
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.chrome.ChromeOptions;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.OutputType;
public class Example {
public static void main(String[] args) {
// Path to the ChromeDriver executable.
System.setProperty("webdriver.chrome.driver", "D:/CEFTesting/chromedriver.exe");
// Path to the CEF executable.
ChromeOptions options = new ChromeOptions();
options.setBinary("D:/CEFTesting/cef_binary_3.2924.1564.g0ba0378_windows64_client/Release/cefclient.exe");
WebDriver driver = new ChromeDriver(options);
driver.get("http://www.google.com/xhtml");
sleep(3000); // Let the user actually see something!
WebElement searchBox = driver.findElement(By.name("q"));
searchBox.sendKeys("ChromeDriver");
searchBox.submit();
sleep(5000); // Let the user actually see something!
String screenshotBase64 = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BASE64);
System.out.println(screenshotBase64);
sleep(5000); // Let the user actually see something!
driver.quit();
}
}
I am facing the error.
I'm using the following:
CEF application - Sample application provided by CEF (link - https://bitbucket.org/chromiumembedded/cef/wiki/UsingChromeDriver.md)
selenium jar - selenium-server-standalone-3.0.1
cef_binary_3.2924.1564.g0ba0378_windows64_client
chromedriver
Here is the code:
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.chrome.ChromeOptions;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.OutputType;
public class Example {
public static void main(String[] args) {
// Path to the ChromeDriver executable.
System.setProperty("webdriver.chrome.driver", "D:/CEFTesting/chromedriver.exe");
// Path to the CEF executable.
ChromeOptions options = new ChromeOptions();
options.setBinary("D:/CEFTesting/cef_binary_3.2924.1564.g0ba0378_windows64_client/Release/cefclient.exe");
WebDriver driver = new ChromeDriver(options);
driver.get("http://www.google.com/xhtml");
sleep(3000); // Let the user actually see something!
WebElement searchBox = driver.findElement(By.name("q"));
searchBox.sendKeys("ChromeDriver");
searchBox.submit();
sleep(5000); // Let the user actually see something!
String screenshotBase64 = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BASE64);
System.out.println(screenshotBase64);
sleep(5000); // Let the user actually see something!
driver.quit();
}
}
below is the code : im not able launch the browser using the code . please suggest the solution
import org.openqa.selenium.Test;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.Assert;
import org.testng.annotations.*;
public class NewTest {
public WebDriver driver;`enter code here`
#Test
public void VerifyHomepageTitle() {
WebDriver driver = new FirefoxDriver();
driver.navigate().to("http://google.com");
driver.quit();
}
}
You are closing the web page immediately after opening using 'driver.quit()'. Comment this code and try you will see the difference.
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
Hi I am learning selenium grid for the first time.I am unable to understand why Desired capabilities class is used to set browser name and platform details in a remote machine.
please let me know if there is any proper documentation on it apart from google-wiki page
Thanks
prathima
Not all remote machines (or sessions) support the features requested by a user. E.g. user may want to use Chrome on Windows but some machines are only running Firefox on Linux.
The desiredCapabilities is used to describe the features of a session requested by user. You can refer to this link and this link for more info.
- when user send request to remote machine to run a particular test on
a particular browser on a particular platform.
- It doesn't mean that all the remote machine will support all the
features requested by user such as (Particular browser on a
particular machine).
**Example:**
- If user request to execute a testcase on internet explorer on Linux
platform. It doesn't mean that always Linux machine has internet
explorer it would have firefox not internet Explorer(Because it is
open source).
- Linux machine doesn't support the features requested by a User. so
that, that point of time we will use DesiredCapabilites class to set
the platform , Browser Name and version of browser of Remote Machine
to execute the Test.
Example:
package grid;
import static org.junit.Assert.*;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class SimpleGridTest
{
WebDriver driver;
String baseUrl , nodeUrl;
#Before
public void setUp() throws Exception
{
WebDriver driver;
String baseUrl , nodeUrl;
baseUrl = "https://www.facebook.com";
nodeUrl = "http://192.168.10.21:5568/wd/hub";
DesiredCapabilities capability = DesiredCapabilities.firefox();
capability.setBrowserName("firefox");
capability.setPlatform(Platform.WIN8_1);
driver = new RemoteWebDriver(new URL(nodeUrl),capability);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(2, TimeUnit.MINUTES);
}
#Test
public void test() throws InterruptedException
{
driver.manage().window().maximize();
driver.get("https://www.google.co.in");
driver.findElement(By.linkText("Gmail")).click();
driver.findElement(By.id("Email")).sendKeys("abc#gmail.com");
driver.findElement(By.id("Passwd")).sendKeys("1234");
driver.findElement(By.id("signIn")).click();
}
#After
public void tearDown() throws Exception
{
driver.quit();
}
}