Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java isSelected()上的AssertTrue测试用例失败,但应通过_Java_Selenium - Fatal编程技术网

Java isSelected()上的AssertTrue测试用例失败,但应通过

Java isSelected()上的AssertTrue测试用例失败,但应通过,java,selenium,Java,Selenium,我是Selenium/Java的新手。我有两个测试用例,其中我使用isSelected()方法断言单选按钮元素。当我在未选择的元素上断言False时,第一个测试用例通过。但是,第二个测试用例失败,但应该通过:我在选中的元素(未指定的单选按钮)上断言True。我在我所做的事情中找不到逻辑错误。我不确定这是否可能是一个时间问题 public class RegistrationPage extends TestBase{ //Object Repository - Page Factory @Fi

我是Selenium/Java的新手。我有两个测试用例,其中我使用isSelected()方法断言单选按钮元素。当我在未选择的元素上断言False时,第一个测试用例通过。但是,第二个测试用例失败,但应该通过:我在选中的元素(未指定的单选按钮)上断言True。我在我所做的事情中找不到逻辑错误。我不确定这是否可能是一个时间问题

public class RegistrationPage extends TestBase{

//Object Repository - Page Factory
@FindBy(xpath="//label[contains(text(), 'Male')]")
        WebElement maleRadioBtn;

@FindBy(xpath="//label[contains(text(), 'unspecified')]")
        WebElement unspecifiedRadioBtn;

@FindBy(name="agree")
    WebElement agreeChbx;

@FindBy(id="SubmitButton")
    WebElement submitBtn;

//Initializing the Page Objects:
    public RegistrationPage(){
        PageFactory.initElements(driver, this);
    }

//Registration Page Actions
public boolean validateMaleRadioBtn(){
    return maleRadioBtn.isSelected();
}

public boolean validateUnspecifiedRadioBtn(){
    return unspecifiedRadioBtn.isSelected();
}

public void clickAgree(){
    agreeChbx.click();
}

public boolean validateSubmitBtn(){
    return submitBtn.isEnabled();
}
}


public class RegistrationPageTest extends TestBase{

HomePage homePage;
RegistrationPage registrationPage;

public RegistrationPageTest() {
    super();
}


@BeforeMethod
public void setUp() {
    initialization();
    homePage = new HomePage();
    homePage.clickSignUp();
    registrationPage = new RegistrationPage();      
}

@Test(priority = 1)
public void maleChbxTest() {
    boolean flag = registrationPage.validateMaleRadioBtn();
    Assert.assertFalse(flag);
}

@Test(priority = 2)
public void unspecifiedRadioBtnTest() {
    boolean state = registrationPage.validateUnspecifiedRadioBtn();
    Assert.assertTrue(state);
}

@AfterMethod
public void tearDown() {
    driver.quit();
}
}




java.lang.AssertionError: expected [true] but found [false]
at org.testng.Assert.fail(Assert.java:96)
at org.testng.Assert.failNotEquals(Assert.java:776)
at org.testng.Assert.assertTrue(Assert.java:44)
at org.testng.Assert.assertTrue(Assert.java:54)
at com.qa.testcases.RegistrationPageTest.unspecifiedRadioBtnTest(RegistrationPageTest.java:41)
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.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

您应该寻找一些关于XPath的教程,因为这不是学习技能的理想场所

对于您的特定情况,您可以使用以下XPath之一:

  • //标签[包含(text(),'unspecified')]/input
    这将选择
    标签下的
    input
    标记,该标签必须包含文本“unspecified”
  • //输入[@type='radio'][3]
    这将选择第三个单选按钮
  • //输入[@value='']
    这将选择具有空值的输入(其他两个具有不同的值)

可能还有其他选择。

您应该寻找一些关于XPath的教程,因为这不是学习技能的理想场所

对于您的特定情况,您可以使用以下XPath之一:

  • //标签[包含(text(),'unspecified')]/input
    这将选择
    标签下的
    input
    标记,该标签必须包含文本“unspecified”
  • //输入[@type='radio'][3]
    这将选择第三个单选按钮
  • //输入[@value='']
    这将选择具有空值的输入(其他两个具有不同的值)

可能还有其他选择。

您的
未指定的DRADIOBTN
可通过
xpath=“//标签…”
找到。单选按钮通常是
输入
。给我们看看你的DOM,也许我们能帮上忙。我真的很感谢你的回复。如果我在这里很愚蠢,我向你道歉。我有一些DOM的感觉,但不是完全的。(未指明)。我使用了CroPath建议的Rel XPath。作为参考,我正在练习。请用附加信息编辑您的问题。为了在这里得到更好的答案,请考虑使用,特别是阅读通过。您的<代码>未指定的ReaBoTn< <代码>由<代码> xPath =“//Label.…”< /代码>找到。单选按钮通常是
输入
。给我们看看你的DOM,也许我们能帮上忙。我真的很感谢你的回复。如果我在这里很愚蠢,我向你道歉。我有一些DOM的感觉,但不是完全的。(未指明)。我使用了CroPath建议的Rel XPath。作为参考,我正在练习。请用附加信息编辑您的问题。为了得到更好的答案,请考虑阅读,尤其是阅读。再次感谢你的回答。我一直在练习XPath(除了依赖CroPath之外),但这肯定告诉我我还有更多的东西要学。再次感谢您抽出时间回复。我一直在练习XPath(除了依赖CroPath之外),但这肯定告诉我还有更多需要学习的地方。