Web-Treiber und Fluent Wait ist zwischen den Methoden in TestNG nullJava

Java-Forum
Guest
 Web-Treiber und Fluent Wait ist zwischen den Methoden in TestNG null

Post by Guest »

Ich bin relativ neu im Selenium -Web -Treiber und testng. lebend zwischen @test methods. Dies resultiert zu diesem Fehler: < /p>
java.lang.nullpointerexception: Kann nicht "org.openqa.selenium.webdriver () "Ist null < /p>
weiß jemand, warum dies passieren könnte? < /p>

Code: Select all

public class baseTest {

protected static ThreadLocal driver = new ThreadLocal();
protected static ThreadLocal wait = new ThreadLocal();
protected SoftAssert softAssert;

@BeforeSuite
public void setUpSuite() {
System.out.println("Executing method - setUpSuite\n\n");
}

@AfterSuite
public void tearDownSuite() {
System.out.println("Executing method - tearDownSuite\n\n");
// Cleanup
if (driver.get() != null) {
driver.get().quit();
driver.remove();
}
if (wait.get() != null) {
wait.remove();
}
}

@BeforeClass
public void setUpClass() {
System.out.println("Executing method - setUpClass\n\n");

configProp config = new configProp();
driver.set(config.initializeDriver());
wait.set(config.initializeFluentWait(driver.get())); // Initialize FluentWait before the class

// Perform login
config.login(driver.get());
System.out.println("Performed login\n\n");

// Call the testPostmanAuth class
System.out.println("Calling PostmanAuth\n\n");

TestPostmanAuth postmanAuth = new TestPostmanAuth();
try {
postmanAuth.testAuthorizationLoginOnPostman();
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
}

@AfterClass
public void tearDownClass() {
System.out.println("Executing method - tearDownClass\n\n");

// Cleanup for the current class
if (driver.get() != null) {
driver.get().quit();
driver.remove();
}
if (wait.get() != null) {
wait.remove();
}
}

@BeforeMethod
public void beforeMethod() {
System.out.println("Executing method - beforeMethod\n\n");
softAssert = new SoftAssert(); // Initialise SoftAssert before each test method

// Check if driver and wait are initialised
if (driver.get() == null || wait.get() == null) {
throw new RuntimeException("WebDriver or FluentWait instance is not initialized.");
}
}

@AfterMethod
public void afterMethod() {
System.out.println("Executing method - afterMethod\n\n");
softAssert.assertAll(); // Ensure assertAll is called after each test method

}

// Getters for driver and wait
public WebDriver getDriver() {
return driver.get();
}

public FluentWait getWait() {
return wait.get();
}
}
Der Treiber und das fließende Warten werden in einer anderen Datei initialisiert:

Code: Select all

public class configProp {

public WebDriver initializeDriver() {
System.setProperty("webdriver.gecko.driver",
"URLGoesHere");

FirefoxOptions options = new FirefoxOptions();
options.setCapability("webSocketUrl", true); // Enable WebDriver BiDi

WebDriver driver = new FirefoxDriver(options);
driver.manage().window().maximize();
return driver;
}

public FluentWait initializeFluentWait(WebDriver driver) {
// Initialise FluentWait
FluentWait  wait = new FluentWait(driver).withTimeout(Duration.ofSeconds(20))
.pollingEvery(Duration.ofMillis(500)).ignoring(NoSuchElementException.class);
return wait;
}
Dann gibt es zwei weitere Dateien, in denen die BaseTest-Klasse erweitert wird.
In diesen beiden anderen Dateien befinden sich die @Test-Methoden.
Vollständiger Fehler: Bestimmte Teile für Beitrag entfernt:

Code: Select all

checkIncident
java.lang.RuntimeException: WebDriver or FluentWait instance is not initialized.
at Automation.baseTest.beforeMethod(baseTest.java:81)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
at java.base/java.lang.Thread.run(Thread.java:1575)
... Removed 15 stack frames
(Checks incident number sent matches on website)

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post