Reputation:
Problem: I am a beginner with selenium and automation testing and I am writing a selenium script using java, TestNG, and maven. When I write everything in one class, all works fine, but I want to have a package for all objects, a package for tests, and Base Class with the main setting. The project will contain a class for every page from the website and a class for all tests.
What I tried: When I try to modify something appear another error is from the constructor in BaseClass and I have no idea why The base class is this: I tried with
public BaseClass(WebDriver driver) {
this.driver = driver;
PageFactory.initElements(driver, this);
}
or PagegeFactory.initElements(new AjaxElementLocatorFactory(driver, TimeoutValue), this);
and didn't work.
Upvotes: 0
Views: 880
Reputation: 14746
The basic problem with your code is that you have parameterised your constructor.
TestNG ONLY knows how to invoke the default constructor (no arguments constructor). In your case, you have a parameterised constructor that seems to accept a WebDriver driver
instance and TestNG does not know how to instantiate this.
The easiest fix to get past this problem would be to do the following:
AnalizesiPreturi
violates this expectation)Sometime back I built a library called autospawn
which uses an annotation driven approach for browser instance management.
You can refer to https://github.com/RationaleEmotions/autospawn#how-to-use-testng
Alternatively you can make use of TestNG listeners using which you can instantiate webdriver instance and make it available via a ThreadLocal
instance.
For more details please refer to my blog post https://rationaleemotions.com/parallel_webdriver_executions_using_testng/
Upvotes: 0