英文:
Assert Test wont pass, just - Selenium issues
问题
以下是翻译好的代码部分:
package Key;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.junit.Test;
import org.junit.Assert;
public class KeyEvent {
@Test
public void keyEventTest() throws Exception {
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://the-internet.herokuapp.com/key_presses");
driver.manage().window().maximize();
Actions action = new Actions(driver);
action.sendKeys(Keys.SPACE).build().perform();
String text = driver.findElement(By.id("result")).getText();
System.out.println(text);
Assert.assertEquals(text, "You entered: Space");
}
}
英文:
I am currently conducting the following piece of automated cod. It works automatically but when it gets to the key assert test, it does not work. Any suggestions why my code is failing
package Key;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.junit.Test;
import org.junit.Assert;
public class KeyEvent {
@Test
public void keyEventTest() throws Exception {
System.setProperty("webdriver.chrome.driver","C:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://the-internet.herokuapp.com/key_presses");
driver.manage().window().maximize();
Actions action= new Actions (driver);
action.sendKeys(Keys.SPACE).build().perform();
String text = driver.findElement(By.id("result")).getText();
System.out.println(text);
Assert.assertEquals (text,"You entered : Space");
}
答案1
得分: 1
这只是一个简单的拼写错误吗?
断言区分大小写和空白符。
将应用程序手动生成的内容与您的预期内容进行比较:
-
您输入:
You entered : Space
-
我的 Chrome 显示:
You entered: SPACE
我的显示效果如下:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论