【发布时间】:2018-09-05 08:21:17
【问题描述】:
我一直在尝试练习 Selenium,但由于电子邮件验证,我无法测试注册功能,但每次我运行测试时,它都会输入除“@”符号之外的所有内容,显然这是一个必需的字符. 这是网站,我一直在测试 -> http://a.testaddressbook.com/ (对不起,如果搞砸了,这是我第一次在这里发帖)
预期结果: yolo@test.com(将显示在电子邮件输入字段中)
实际结果: yolotest.com without "@"
步骤定义文件(它的重要部分): StepDef.java
以及引用步骤定义文件的页面: SignUp.java
编辑:我从 Eclipse 开始,然后改用 IntelliJ(希望这只是 IDE 设置问题,但不值得一试)。 我还尝试添加“@”符号的unicode,它仍然没有输入“@”。
按照要求,您可以在下面找到代码的 sn-ps: SignUp.java(页面)
package Pages;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.FindBy;
public class SignUp {
@FindBy(id = "user_email")
private WebElement userName;
@FindBy(id = "user_password")
private WebElement userPass;
public void credentials(WebDriver driver) {
Actions cred = new Actions(driver);
cred.click(userName).sendKeys("yolo@test.com").perform();
cred.click(userPass).sendKeys("Batman").perform();
}
}
StepDef.java(步骤定义文件)
@Then("^I fill out fields with information$")
public void i_fill_out_fields_with_information() throws Throwable {
SignUp filldetails = PageFactory.initElements(driver, SignUp.class);
filldetails.credentials(driver);
Thread.sleep(2000);
}
编辑(建议代码):
package com.qa.quickstart.Bookthing;
import static org.junit.Assert.*;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class TestThing {
ChromeDriver driver;
String url="http://a.testaddressbook.com/sign_in";
@Test
public void test() throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Laptop\\eclipse-workspace\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get(url);
WebDriverWait wait = new WebDriverWait(driver, 50);
driver.findElement(By.linkText("Sign up")).click();
WebElement button = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@value='Sign up']")));
WebElement email = wait.until(ExpectedConditions.elementToBeClickable(By.id("user_email")));
email.sendKeys("apple@test.com");
WebElement pass = wait.until(ExpectedConditions.elementToBeClickable(By.id("user_password")));
pass.sendKeys("banana");
Thread.sleep(15000);
}
}
【问题讨论】:
-
以文本形式发布您的代码,而不是发布屏幕截图。它将提高问题的可读性和可搜索性。
-
我怀疑字符集有问题。使用的默认字符集是什么?
-
是的,正在使用默认字符集,我什么都没碰。事实上,我最近才安装了这些 IDE(Eclipse、IntelliJ)。
-
以防万一,我查了一下,它是默认字符集(Cp1252)
标签: selenium automated-tests email-validation