我正在尝试使用Eclipse Luna在Safari上使用Selenium测试我的网站。
我的网站使用Twitter登录。
当我尝试将密钥发送到api.twitter.com上的输入时,我有一个超时。
请注意,我已经尝试过"发送密钥"在谷歌使用Selenium的维基页面甚至在www.twitter.com上,它工作正常。
我不明白为什么它不能在api.twitter.com上工作 我认为问题是我的网站,然后我在另一个网站上使用twitter身份验证测试了相同的代码,我也遇到了同样的错误。
我甚至尝试使用javascriptExecutor来填充输入的值,我也有一段时间。
有人可以帮助我吗?
请在下面找到我的代码和我在控制台中的跟踪。
package com.fxlabs.wonderboard.nodeTest;
import static org.junit.Assume.assumeTrue;
import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.safari.SafariDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class BrowserTest {
private WebDriver driver = null;
private static boolean isSupportedPlatform() {
Platform current = Platform.getCurrent();
return Platform.MAC.is(current) || Platform.WINDOWS.is(current);
}
@Before
public void createDriver() {
assumeTrue(isSupportedPlatform());
driver = new SafariDriver();
}
@After
public void quitDriver() {
driver.quit();
}
@Test
public void shouldBeAbleToPerformAGoogleSearch() {
driver.get("http://tweetbeam.com");
new WebDriverWait(driver, 3).until(ExpectedConditions.titleIs("TweetBeam Twitter Wall - Visualize Live Tweets"));
driver.findElement(By.className("navbar-right")).findElement(By.tagName("a")).click();
new WebDriverWait(driver, 3).until(ExpectedConditions.titleIs("Twitter / Autoriser une application"));
driver.findElement(By.id("username_or_email")).sendKeys("TwitterUsername");
driver.findElement(By.id("username_or_email")).sendKeys("password");
}
}
失败追踪:
org.openqa.selenium.TimeoutException: Timed out awaiting response to command "sendKeysToElement" after 30001 ms (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 30.01 seconds
Build info: version: '2.44.0', revision: '76d78cf323ce037c5f92db6c1bba601c2ac43ad8', time: '2014-10-23 13:11:40'
System info: host: 'xxx', ip: 'xxx', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.5', java.version: '1.6.0_65'
Session ID: null
Driver info: org.openqa.selenium.safari.SafariDriver
Capabilities [{platform=MAC, cssSelectorsEnabled=true, javascriptEnabled=true, secureSsl=true, browserName=safari, takesScreenshot=true, version=7.1.4}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:268)
at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:89)
at com.fxlabs.wonderboard.nodeTest.BrowserTest.shouldBeAbleToPerformAGoogleSearch(BrowserTest.java:44)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
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.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
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.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
答案 0 :(得分:0)
您是否尝试将电子邮件和密码发送到您不在的同一个字段?
driver.FindElement(By.Id("username_or_email")).SendKeys("TwitterUsername");
driver.FindElement(By.Id("password")).SendKeys("password");
这对我来说很好。
但请注意,如果页面检测到您已登录到Twitter,则页面行为会有所不同。你得到一个欢迎你的对话框弹出窗口。