ChromeDriver and WebDriver for Selenium through TestNG results in 4 errors
There are exactly 4 errors as follows:
Error: ChromeDriver cannot be resolved to a type
Solution: You need to add the following import
import org.openqa.selenium.chrome.ChromeDriver;
- Here you can find a discussion on chrome Webdriver can't be resolved to a type error eclipse and java
Error: Test cannot be resolved to a type
Solution: You need to add the following import
import org.testng.annotations.Test;
//or
import org.junit.Test;
Error: The public type ChromeTest must be defined in its own file
Solution: Your filename is Chrom.java but your classname is ChromeTest where as both should have been similar. Change them as identical.
Here you can find a discussion on “The public type must be defined in its own file” but the file name and the class name is the same
Error: WebDriver cannot be resolved to a type
Solution: You need to add the following import
import org.openqa.selenium.WebDriver;
Best Practice
- You have to keep the filename (currently Chrom.java) and your classname (currently ChromeTest) identical as a mandatory measure.
- You need to mention the related imports whenever you are using any class. You can Mouse Hover over the error and choose the relevant import.
- You should either add the testng jars or the junit jars but not both of them.
Webdriver instances - how to run multiple tests using one test base
StaleElementReferenceException
is thrown when the element you're looking for is no longer attached to the DOM. Most probably you're trying to .findElement first, then DOM gets refreshed and you're trying to access it. This often happens with parallel tests execution if your page-class instances with elements are not thread-safe.
Try to use:
object _lock = new object();
lock (_lock)
{
//your driver initialization/login
}
You should also define how many threads will be executing your tests by modifying thread-count="5" parallel="methods"
Related Topics
Hibernate Saveorupdate Behavior
How to Save Preference User Settings in Java
How to Solve the 'Classic' Knapsack Algorithm Recursively
Why Does the "Protected" Modifier in Java Allow Access to Other Classes in Same Package
How to Create Change Listener for Variable
How to Run a Java Program Without Main Method
How to Find the Console Width with Java
Sum Values from Specific Field of the Objects in a List
Does the Sequence of the Values Matter in a JSON Object
When Does the JPA Set a @Generatedvalue @Id
What Is the Purpose of 'Class.Forname("My_Jdbc_Driver")'
How to Use Yamlpropertiesfactorybean to Load Yaml Files Using Spring Framework 4.1
How to Disable or Bypass Hardware Graphics Acceleration(Prism) in Javafx
Java: How to Access a Class's Field by a Name Stored in a Variable
What Is the Priority of Casting in Java
Java Interfaces Methodology: Should Every Class Implement an Interface