這裏我已經構建了2個類,我想在類Testjava中使用函數「User_mgmt_A」。 我的第一類: - 公共類testjava延伸User_mgmt {如何在運行一個selenium項目時使用java中另一個類的一個類的功能
void valid_login()
{
System.setProperty("webdriver.chrome.driver", "C:/Users/neha.sharma/Downloads/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://192.168.127.54:8080/TNSRDH/login");
BufferedReader br1= new BufferedReader(new InputStreamReader(System.in));
String user="test4pds";
System.out.print("Enter the username for the Tamil Nadu project");
try {
user=br1.readLine();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
driver.findElement(By.id("username")).sendKeys(user);
BufferedReader br2= new BufferedReader(new InputStreamReader(System.in));
String pwd = "[email protected]";
System.out.println("Enter the password for Tamil Nadu project");
try {
pwd=br2.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
driver.findElement(By.id("txtPassword")).sendKeys(pwd);
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
Select department=new Select(driver.findElement(By.name("department")));
department.selectByIndex(3);
driver.findElement(By.id("btn")).click();
public static void main(String args[]) throws IOException
{
testjava login= new testjava();
User_mgmt mgmt=new User_mgmt();
login.valid_login();
mgmt.User_mgmt_A();
}
---------------------------------------------------------
My 2nd class:-
public class User_mgmt {
void User_mgmt_A() throws IOException
{
System.setProperty("webdriver.chrome.driver", "C:/Users/neha.sharma/Downloads/chromedriver.exe");
WebDriver driver = new ChromeDriver();
/*driver.get("http://192.168.127.54:8080/TNSRDH/login");
driver.findElement(By.id("username")).sendKeys("Test4pds");
driver.findElement(By.id("txtPassword")).sendKeys("[email protected]");
Select department=new Select(driver.findElement(By.name("department")));
department.selectByIndex(3);
driver.findElement(By.id("btn")).click(); */
WebDriverWait wait = new WebDriverWait(driver, 4000);
wait.until(ExpectedConditions.visibilityOfElementLocated((By.id("id"))));
driver.findElement(By.xpath("//a[contains(.,'User Management')]")).click(); //selecting user management icon
driver.findElement(By.xpath("//a[contains(@href,'showUserSubModule?submodule=userCreation')]")).click(); // selecting 'User creation' link
driver.findElement(By.xpath("//img[(@src='images/adduser.png')]")).click(); // selecting 'Add user' link
driver.findElement(By.xpath(".//*[@id='userform']/div[4]/div[2]/div/button")).click(); // selecting department in Add user form
driver.findElement(By.xpath(".//*[@id='userform']/div[4]/div[2]/div/div/ul/li[2]/label/input")).click(); // selecting 'CMUPT' Department
driver.findElement(By.id("firstName")).sendKeys("ArunTester");
driver.findElement(By.id("middleName")).sendKeys("Srinivas");
driver.findElement(By.id("lastName")).sendKeys("B");
driver.findElement(By.id("loginName")).sendKeys("ArunTester12");
/* List RadioBtn= (List) driver.findElement(By.xpath("//div[@class='col-lg-4 col-md-4 col-xs-4 col-sm-4']"));
BufferedReader Radio= new BufferedReader(new InputStreamReader(System.in));
String radioM="Male";
radioM=Radio.readLine();
if (radioM.equals(Radio))
{
driver.findElement(By.id("sex1")).click();
}
driver.findElement(By.id("sex")).click();
*/
}
private WebElement RadioBtn(int i) {
// TODO Auto-generated method stub
return null;
}
public static void main(String args[]) throws IOException
{
System.exit(0);
}
}
請讓我知道如何才能函數不同的類中調用。我嘗試使用「擴展」關鍵字,但它沒有奏效。
我嘗試使用'Extend'關鍵字&當我執行我的第一個類,即testjava。它向我顯示一個錯誤,說「無法找到元素:{」method「:」id「,」selector「:」username「}」。你可以讓我知道它的解決方案。 –
如何才能逐一調試Eclipse應用程序,以便知道特定LOC存在的問題。 –
通過這個鏈接http://www.vogella.com/tutorials/EclipseDebugging/article.html,它會給你的Eclipse代碼調試的基礎知識 –