断言测试无法通过,只是 – Selenium 出了问题

huangapple go评论73阅读模式
英文:

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

我的显示效果如下:

断言测试无法通过,只是 – Selenium 出了问题

英文:

Is it as simple as a typo?

Asserts are case sensitive & white space sensitive.

Compare what the application produces manually to what you expect:

  • You have: You entered : Space

  • My Chrome has You entered: SPACE

This is how mine looks:

断言测试无法通过,只是 – Selenium 出了问题

huangapple
  • 本文由 发表于 2020年10月18日 20:38:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/64413394.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定