업데이트 된 코드를 초기화되지 않습니다@FindBy의 WebElements는 PageFactory/페이지 개체 프레임 워크에
public class TestBase implements Config {
public WebDriver driver;
//a bunch of methods to handle Driver instantiation and kill
//a bunch of Webdriver utility methods including:
public void click(WebElement element) {
waitForIsDisplayed(element, 120);
element.click();
}
public Boolean waitForIsDisplayed(WebElement element, Integer... timeout) {
try {
waitFor(ExpectedConditions.visibilityOf(element),
(timeout.length > 0 ? timeout[0] : null));
} catch (org.openqa.selenium.TimeoutException exception) {
return false;
}
return true;
}
private void waitFor(ExpectedCondition<WebElement> condition, Integer timeout) {
timeout = timeout != null ? timeout : 5;
WebDriverWait wait = new WebDriverWait(driver, timeout);
wait.until(condition); //java.lang.reflect.UndeclaredThrowableException HERE...Caused by NoSuchElementException
}
프레임 워크가 예상 조건 기다림을 존중하지 않는 것처럼 보입니다 - 요소의 가시성. 에 의한
java.lang.reflect.UndeclaredThrowableException
at com.sun.proxy.$Proxy7.findElement(Unknown Source)
at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:69)
at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38)
at com.sun.proxy.$Proxy9.isDisplayed(Unknown Source)
at org.openqa.selenium.support.ui.ExpectedConditions.elementIfVisible(ExpectedConditions.java:302)
at org.openqa.selenium.support.ui.ExpectedConditions.access$100(ExpectedConditions.java:41)
at org.openqa.selenium.support.ui.ExpectedConditions$10.apply(ExpectedConditions.java:288)
at org.openqa.selenium.support.ui.ExpectedConditions$10.apply(ExpectedConditions.java:285)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:238)
at com.multicom.fabrix.framework.TestBase.waitFor(TestBase.java:152)
at com.multicom.fabrix.framework.TestBase.waitForIsDisplayed(TestBase.java:141)
at com.multicom.fabrix.pageobjects.CustomerHomePage.waitForResults(CustomerHomePage.java:75)
at com.multicom.fabrix.regressiontests.FlightBookingTest.searchForAPackage(FlightBookingTest.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:643)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:782)
at org.testng.TestRunner.run(TestRunner.java:632)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.run(TestNG.java:1064)
at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:74)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:121)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.mycompany.mymodule.webdriver.WebDriverInvoker.invokeNormally(WebDriverInvoker.java:47)
at com.mycompany.mymodule.webdriver.WebDriverInvoker.invoke(WebDriverInvoker.java:38)
... 41 more
: 나는의 구현과 함께 할 수있는 뭔가 'visibilityOf (요소)'와 @FindBy이 요소 예외의
스택 추적을 초기화한다 방법을 생각 org.openqa.selenium.NoSuchElementException을 : 해당 요소가 없습니다 : 요소를 찾을 수 없습니다 : { "method": "xpath", "selector": ".//*[ id = 'container']/div/div [3]/div/div [1]/div/h3 "}
감사합니다. Works as explained – Steerpike
내가이 단계에서 실제로 이해하지 못하는 이유는 NoSuchElementExceptions와 함께 FindBy의 폭탄을 사용하는 모든 방법이 왜 이유일까요? 중단 점을 사용하여 디버깅 할 때 테스트가 정상적으로 실행됩니다. 그래서 FindBy와 동기화 문제가 있습니다. WebDriver가 관련 페이지 나 페이지 영역으로 이동하기 전에 initElements가 로케이터를 찾으려고합니까? 테스트마다 필자는 여러 다른 PageObjects를 참조하기 때문에 FindBy 's 중 일부는 페이지가로드되기 전에 초기화하려고 할 수 있습니다. – Steerpike
PageFactory.initElements는 @FindBy 주석으로 표시된 WebElement 필드에 대한 프록시 만 제공하기 때문에 PageObjects를 초기화하는 위치는 중요하지 않습니다. 그러나 이러한 필드에 액세스 할 때 sendkeys 나 click과 같은 메소드를 사용하려면 브라우저가 올바른 페이지에 있는지 확인해야합니다. 현재 URL을 PageObject에 대해 원하는 것과 비교하거나 LoadableComponent 클래스를 살펴볼 수 있습니다. 디버그 모드에서 사라지는 NoSuchElementExceptions를 얻으려면 WebDriverWait 및 ExpectedConditions 클래스를 사용하여 제대로 동기화해야합니다. – Grasshopper