0
// Login.java文件,我已經執行了這個文件,其中我給了TestG註解但結果顯示沒有方法執行。而執行該代碼,並導致測試NG產生沒有這樣的方法執行使用測試NG註釋
import java.util.concurrent.TimeUnit;
import org.testng.*;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Login {
public static FirefoxDriver _webBrowser;
public String _url;
@Test(priority = 1, enabled = true)
public Login(FirefoxDriver driver, String url) {
_webBrowser = driver;
_url = url;
}
@Test(priority = 2)
private boolean openBrowser() {
boolean isSuccess = false;
try {
_webBrowser.manage().window().maximize();
_webBrowser.get(_url);
_webBrowser.manage().timeouts().implicitlyWait(120,TimeUnit.SECONDS);
isSuccess = true;
} catch (Exception ex) {
}
return isSuccess;
}
@Test(priority = 3)
public boolean doLogin(String username, String password) {
boolean isSuccess = false;
try {
if (openBrowser()) {
Login module = new Login(_webBrowser, "http://180.211.114.147:97/Account/Login");
module.doLogin("devrana","dev123");
_webBrowser.findElement(By.id("UserName")).sendKeys(username);
_webBrowser.findElement(By.id("Password")).sendKeys(password);
_webBrowser.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS);
_webBrowser.findElement(By.id("btnLogin")).submit();
String tmp = _webBrowser.getCurrentUrl();
if (tmp.equals("http://180.211.114.147:97/#/app/dashboard"))
System.out.println("Login success!!");
else
System.out.println("Fail to login..");
}
} catch (Exception ex) {
}
return isSuccess;
}
}
控制檯輸出顯示測試1/1方法:0(194ms)
Default suite
Total tests run: 0, Failures: 0, Skips: 0
===============================================
[TestNG] Time taken by [email protected]: 1 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 7 ms
[TestNG] Time taken by [email protected]: 35 ms
[TestNG] Time taken by [email protected]: 4 ms
[TestNG] Time taken by org.test[email protected]: 126 ms
[TestNG] Time taken by [email protected]: 20 ms