Selenium Webdriver를 처음 사용하고이 API를 배우려고합니다. 하나의 테스트에서 여러 어설 션을 효과적으로 사용하는 방법을 알고 싶습니다. 직접적으로 사용하려고 시도했지만 코드 길이가 길어지고 디버깅하기가 매우 어렵습니다. 어떤 제안이라도 끝내는 방법?Java의 webdriver에서 여러 어설 션을 사용하는 방법
package com.eureqa.scripts;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
public class Phase1 {
public static WebDriver driver;
public static WebDriver driver1;
public void navigation1(WebDriver driver1)
{
boolean result=verifyElementPresent(driver1);
if(result)
{
System.out.println("Element found");
}
else
{
System.out.println("Element not found");
}
driver1.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
boolean result1=assertElementPresent(driver1);
if(result1)
{
System.out.println("Element asserted");
}
else
{
System.out.println("Element not asserted");
driver1.quit();
}
driver1.findElement(By.linkText("Reports")).click();
}
public boolean verifyElementPresent(WebDriver driver1)
{
try{
driver1.findElement(By.id("commonheader:headerForm:projectlist"));
return true;
}catch(Exception ex)
{
return false;
}
}
public boolean assertElementPresent(WebDriver driver1)
{
try{
driver1.findElement(By.linkText("Reports"));
return true;
}catch(Exception ex)
{
return false;
}
}
public static void main(String arr[]) throws InterruptedException
{
WebDriver driver1=LoginObject.driver();
System.out.println("Object Received");
LoginEureqa m=new LoginEureqa();
m.login(driver1);
Phase1 p1=new Phase1();
p1.navigation1(driver1);
System.out.println();
System.out.println("Phase1 executed successf`enter code here`ully");
}
}
테스트하려는 내용에 대해 자세히 설명해 줄 수 있습니까? 더 나은 코드를 찾고있는 중이거나 지금 가지고있는 것을 실행하려고 할 때 오류가 있습니까? – shri046
다른 자바 파일에서 모든 코드를 사용하여 반복적으로 모든 assertion 메서드를 작성하고 클래스를 가져 와서 필요한 메서드를 사용하여 필요할 때 호출하는 것이 좋습니다. – Subh
내 코드가 이번에는 잘 실행되지만 내 관심사는 여러 번 assaysion 명령을 사용해야합니다. 자바에 별도의 클래스를 생성하고 싶습니다. 모든 유형의 로케이터를 가져올 수있는 메소드를 일반화 할 수 있다면 부울 값을 반환합니다. . 할 수있는 최선의 방법을 제안 해주세요. – Vivek