在我们的应用程序中,我们有两个地方是wie ha自由文本搜索字段。下面是显示扩展搜索选项区域的按钮。这可以在Chrome上使用Selenium Java作为测试工具,但在PhantomJS的一个地方。什么不起作用是通过单击按钮显示扩展选项。
按钮如下所示:
<a id="extendSearch" href="javascript:;"[ngClass]="setToggleExtendedSearchLinkClasses()" (click)="toggleExtendedSearch()">
{{extendSearch | translation}}
<span class="JM_icon-check" [attr.data-check]="isFilterSelected() ? true : false"></span>
</a>
功能&#34; toggleExtendedSearch()&#34;看起来像这样:
toggleExtendedSearch() {
console.log("document-search component: toggleExtendedSearch is called");
if (this.extendedSearchOn) {
this.extendedSearchOn = false;
}
else {
this.extendedSearchOn = true;
}
console.log("document-search component.toggleExtendedSearch:" + this.extendedSearchOn);
}
使用此Angular标记显示扩展搜索选项的区域:
<app-document-search-extended #extendedSearch [hidden]="!extendedSearchOn" (onFilterReset)="resetAllFilters($event)"
(onSubmitFilter)="toggleExtendedSearch()"></app-document-search-extended>
测试用例的代码如下所示:
SyncingWebDriverEventListener.whenStable(driver, extendSearch);
extendSearch.click();
SyncingWebDriverEventListener.whenStable(driver, extendSearch);
Select dropdownFoerderbereiche = new Select(foerderbereiche);
List<WebElement> optionsFoerderbereiche = dropdownFoerderbereiche.getOptions();
LogEntries logs = driver.manage().logs().get("browser");
System.out.println();
System.out.println();
System.out.println("==================== Start Browser Console Log ====================");
System.out.println();
for(LogEntry entry : logs) {
System.out.println(entry.toString());
}
System.out.println();
System.out.println("==================== End Browser Console Log ====================");
System.out.println();
System.out.println();
dropdownFoerderbereiche.selectByIndex(1);
&#34; extendedSearch&#34;是有问题的按钮和&#34; click89&#34;工作没有错误,至少根据Selenium,但它实际上并没有做我应该做的事情。 &#34; dropdownFoerderbereiche.selectByIndex(1);&#34;然后休息,因为&#34; dropdownFoerderbereiche&#34;在上面的点击应该显示的区域内,但不是。因此,Selenium会因为拒绝操纵不可见的元素而中断。
&#34; SyncingWebDriverEventListener.whenStable(driver,extendSearch);&#34;实际上会调用&#34; whenStable()&#34;在以下JS代码中:
(function() {
"use strict";
window.webtest = new function() {
this.markers = {};
this.whenStable = function(callback, element) {
try {
angular.getTestability(element || document.body).whenStable(callback);
} catch (e) {
callback();
}
};
function _sendTimings(callback, angularRequestEnd) {
try {
var timing = {
url : location.href,
navigation : performance.timing,
angular : {
requestEnd : angularRequestEnd
},
resource : performance.getEntries ? performance.getEntries() : null
};
var json = JSON.stringify(timing);
performance.clearResourceTimings && performance.clearResourceTimings();
callback(json);
} catch(e) {
callback(null);
}
}
this.loadMetrics = function(callback) {
try {
angular.getTestability(document.body).whenStable(function() {
_sendTimings(callback, performance.now());
});
} catch(e) {
_sendTimings(callback);
}
};
};
console.log("Webtest js code active.");
})();
错误如下所示:
org.openqa.selenium.ElementNotVisibleException: {"errorMessage":"Element is not currently visible and may not be manipulated","request":{"headers":{"Accept-Encoding":"gzip,deflate","Connection":"Keep-Alive","Content-Length":"27","Content-Type":"application/json; charset=utf-8","Host":"localhost:48906","User-Agent":"Apache-HttpClient/4.5.3 (Java/1.8.0_131)"},"httpVersion":"1.1","method":"POST","post":"{\"id\":\":wdc:1497257910526\"}","url":"/click","urlParsed":{"anchor":"","query":"","file":"click","directory":"/","path":"/click","relative":"/click","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/click","queryKey":{},"chunks":["click"]},"urlOriginal":"/session/44776180-4f4d-11e7-881c-c5c265e80666/element/:wdc:1497257910526/click"}}
Command duration or timeout: 157 milliseconds
Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:49:13 -0700'
System info: host: 'VS2001', ip: '150.201.8.201', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_131'
Driver info: org.openqa.selenium.phantomjs.PhantomJSDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, handlesAlerts=false, databaseEnabled=false, version=2.1.1, platform=XP, browserConnectionEnabled=false, proxy={proxyType=direct}, nativeEvents=true, acceptSslCerts=false, driverVersion=1.2.0, locationContextEnabled=false, webStorageEnabled=false, browserName=phantomjs, takesScreenshot=true, driverName=ghostdriver, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 44776180-4f4d-11e7-881c-c5c265e80666
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:635)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:274)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84)
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.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement$1.invoke(EventFiringWebDriver.java:331)
at com.sun.proxy.$Proxy34.click(Unknown Source)
at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement.click(EventFiringWebDriver.java:344)
at org.openqa.selenium.support.ui.Select.setSelected(Select.java:324)
at org.openqa.selenium.support.ui.Select.selectByIndex(Select.java:179)
at de.lbank.hippo.selenium.pages.DocumentArchivePage.filterDocuments(DocumentArchivePage.java:137)
at de.lbank.hippo.selenium.test.ShowDocumentArchiveTest.filterDocuments(ShowDocumentArchiveTest.java:54)
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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:254)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:193)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
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:147)
Caused by: org.openqa.selenium.remote.ScreenshotException: Screen shot has been taken
Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:49:13 -0700'
System info: host: 'VS2001', ip: '150.201.8.201', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_131'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:142)
... 51 more
Caused by: org.openqa.selenium.ElementNotVisibleException: {"errorMessage":"Element is not currently visible and may not be manipulated","request":{"headers":{"Accept-Encoding":"gzip,deflate","Connection":"Keep-Alive","Content-Length":"27","Content-Type":"application/json; charset=utf-8","Host":"localhost:48906","User-Agent":"Apache-HttpClient/4.5.3 (Java/1.8.0_131)"},"httpVersion":"1.1","method":"POST","post":"{\"id\":\":wdc:1497257910526\"}","url":"/click","urlParsed":{"anchor":"","query":"","file":"click","directory":"/","path":"/click","relative":"/click","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/click","queryKey":{},"chunks":["click"]},"urlOriginal":"/session/44776180-4f4d-11e7-881c-c5c265e80666/element/:wdc:1497257910526/click"}}
Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:49:13 -0700'
System info: host: 'VS2001', ip: '150.201.8.201', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_131'
Driver info: driver.version: unknown
我们还尝试了几秒到几秒钟的简单等待(我认为从5到10或甚至30或60)并且还使用了ngWebDriver(https://github.com/paul-hammant/ngWebDriver)来等待,但这些都没有奏效。它工作的其他代码位置使用以下代码等待它在那里工作,但不适用于此位置。它只在&#34; click()&#34;。
之后才使用它public void waitUntilElementIsPresent(WebElement webElement) {
ExpectedCondition clickableCondition = ExpectedConditions.elementToBeClickable(webElement);
this.waitForCondition(clickableCondition);
}
工作部分的代码是相同的。
在PhantomJS中调用该函数并且&#34; extendedSearchOn&#34;设置为true(我记录了,如您所见)。但尽管如此,该地区仍然隐藏着。因为它在其他地方工作,可能会有副作用,但我绝对不能说出原因。所以也许你可以告诉我你需要哪些额外的信息来阐明它,我很乐意提供它。
我们正在使用Selenium 3.0.1和这里的ng -v:
@angular/cli: 1.0.0-rc.1
node: 6.9.4
os: win32 x64
@angular/common: 2.4.10
@angular/compiler: 2.4.10
@angular/core: 2.4.10
@angular/forms: 2.4.10
@angular/http: 2.4.10
@angular/platform-browser: 2.4.10
@angular/platform-browser-dynamic: 2.4.10
@angular/router: 3.4.10
@angular/cli: 1.0.0-rc.1
@angular/compiler-cli: 2.4.10
@angular/language-service: 4.1.3
谢谢, 扬