Tried implementing calling a java class from a different package to improve the efficiency of my test scripts. Before I rewrite login.java on every class now tried calling it to be more efficient , now what happens is , it logins properly but does not follow up.
Tried separating login.java
package BaseClass;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class Login extends OpenBrowser {
//Open Brower
@Test
public void LoginWebSystem() {
driver.get("http://localhost:82");
WebElement email = driver.findElement(By.id("login_username"));
email.sendKeys("superadmin");
System.out.println("Username Set");
WebElement password = driver.findElement(By.id("login_password"));
password.sendKeys("nelsoft121586");
System.out.println("Password Set");
WebElement login = driver.findElement(By.id("login_submit"));
login.click();
System.out.println("Login Button Clicked");
}
//If login is successful or failed
@Test (priority=1)
public void LoginAccount() {
String newUrl = driver.getCurrentUrl();
if(newUrl.equalsIgnoreCase("localhost:82/controlpanel.php")){
System.out.println("Login Success ");
}
else {
System.out.println("Login Failed");
}
}
//Proceed to product page
}
Test2.java
package BaseClass;
import org.openqa.selenium.*;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.*;
public class test2 extends BaseClass.Login {
WebDriver driver;
@Test (priority=2)
public void ProductPage() {
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.elementToBeClickable(By.partialLinkText("Product")));
driver.findElement(By.partialLinkText("Product")).click();
System.out.println("Successful in proceeding to Product Page");
}
}
Should work properly without no error