Skip to content
Snippets Groups Projects
Verified Commit f130f49f authored by Julien Wittouck's avatar Julien Wittouck
Browse files

:fire: : remove TestCaseFailed exception

parent 495ff2b7
Branches
No related tags found
No related merge requests found
package fr.univlille.gitlab.sra12023.cucumberrunner;
import fr.univlille.gitlab.sra12023.cucumberrunner.selenium.BaseTest;
import fr.univlille.gitlab.sra12023.cucumberrunner.selenium.TestCaseFailed;
import io.cucumber.java.en.Then;
import org.openqa.selenium.WebDriver;
......@@ -178,7 +177,7 @@ public class PredefinedStepDefinitions implements BaseTest {
* @param title :
*/
@Then("^I should\\s*((?:not)?)\\s+see page title as \"(.+)\"$")
public void check_title(String present,String title) throws TestCaseFailed
public void check_title(String present,String title)
{
//System.out.println("Present :" + present.isEmpty());
assertionObj.checkTitle(title,present.isEmpty());
......@@ -186,7 +185,7 @@ public class PredefinedStepDefinitions implements BaseTest {
// step to check element partial text
@Then("^I should\\s*((?:not)?)\\s+see page title having partial text as \"(.*?)\"$")
public void check_partial_text(String present, String partialTextTitle) throws TestCaseFailed
public void check_partial_text(String present, String partialTextTitle)
{
//System.out.println("Present :" + present.isEmpty());
assertionObj.checkPartialTitle(partialTextTitle, present.isEmpty());
......@@ -266,21 +265,21 @@ public class PredefinedStepDefinitions implements BaseTest {
//steps to check link presence
@Then("^link having text \"(.*?)\" should\\s*((?:not)?)\\s+be present$")
public void check_element_presence(String accessName,String present) throws TestCaseFailed, Exception
public void check_element_presence(String accessName,String present)
{
assertionObj.checkElementPresence("linkText",accessName,present.isEmpty());
}
//steps to check partail link presence
@Then("^link having partial text \"(.*?)\" should\\s*((?:not)?)\\s+be present$")
public void check_partial_element_presence(String accessName,String present) throws TestCaseFailed, Exception
public void check_partial_element_presence(String accessName,String present)
{
assertionObj.checkElementPresence("partialLinkText", accessName, present.isEmpty());
}
//step to assert javascript pop-up alert text
@Then("^I should see alert text as \"(.*?)\"$")
public void check_alert_text(String actualValue) throws TestCaseFailed
public void check_alert_text(String actualValue)
{
assertionObj.checkAlertText(actualValue);
}
......
package fr.univlille.gitlab.sra12023.cucumberrunner.selenium;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import java.util.List;
import static org.assertj.core.api.Assertions.fail;
public class AssertionMethods extends SelectElementByType implements BaseTest
{
//This file contains assertion methods which are called from predefinedStepDefinitions
......@@ -25,19 +28,19 @@ public class AssertionMethods extends SelectElementByType implements BaseTest
* @param title : String : expected title
* @param testCase : Boolean : test case [true or false]
*/
public void checkTitle(String title,boolean testCase) throws TestCaseFailed
public void checkTitle(String title,boolean testCase)
{
String pageTitle = getPageTitle();
if(testCase)
{
if(!pageTitle.equals(title))
throw new TestCaseFailed("Page Title Not Matched, Actual Page Title : "+pageTitle);
fail("Page Title Not Matched, Actual Page Title : "+pageTitle);
}
else
{
if(pageTitle.equals(title))
throw new TestCaseFailed("Page Title Matched, Actual Page Title : "+pageTitle);
fail("Page Title Matched, Actual Page Title : "+pageTitle);
}
}
......@@ -45,18 +48,18 @@ public class AssertionMethods extends SelectElementByType implements BaseTest
* @param partialTitle : String : partial title string
* @param testCase : Boolean : test case [true or false]
*/
public void checkPartialTitle(String partialTitle,boolean testCase) throws TestCaseFailed
public void checkPartialTitle(String partialTitle,boolean testCase)
{
String pageTitle = getPageTitle();
if(testCase)
{
if(!pageTitle.contains(partialTitle))
throw new TestCaseFailed("Partial Page Title Not Present, Actual Page Title : "+pageTitle);
fail("Partial Page Title Not Present, Actual Page Title : "+pageTitle);
}
else
{
if(pageTitle.contains(partialTitle))
throw new TestCaseFailed("Partial Page Title Present, Actual Page Title : "+pageTitle);
fail("Partial Page Title Present, Actual Page Title : "+pageTitle);
}
}
......@@ -78,19 +81,19 @@ public class AssertionMethods extends SelectElementByType implements BaseTest
* @param accessName : String : Locator value
* @param testCase : Boolean : test case [true or false]
*/
public void checkElementText(String accessType,String actualValue,String accessName,boolean testCase) throws TestCaseFailed
public void checkElementText(String accessType,String actualValue,String accessName,boolean testCase)
{
String elementText = getElementText(accessType, accessName);
if (testCase)
{
if (!elementText.equals(actualValue))
throw new TestCaseFailed("Text Not Matched");
fail("Text Not Matched");
}
else
{
if (elementText.equals(actualValue))
throw new TestCaseFailed("Text Matched");
fail("Text Matched");
}
}
......@@ -100,19 +103,19 @@ public class AssertionMethods extends SelectElementByType implements BaseTest
* @param accessName : String : Locator value
* @param testCase : Boolean : test case [true or false]
*/
public void checkElementPartialText(String accessType,String actualValue,String accessName,boolean testCase) throws TestCaseFailed
public void checkElementPartialText(String accessType,String actualValue,String accessName,boolean testCase)
{
String elementText = getElementText(accessType, accessName);
if (testCase)
{
if (!elementText.contains(actualValue))
throw new TestCaseFailed("Text Not Matched");
fail("Text Not Matched");
}
else
{
if (elementText.contains(actualValue))
throw new TestCaseFailed("Text Matched");
fail("Text Matched");
}
}
......@@ -132,18 +135,18 @@ public class AssertionMethods extends SelectElementByType implements BaseTest
@param accessName : String : Locator value
@param testCase : Boolean : test case [true or false]
*/
public void checkElementEnable(String accessType, String accessName, boolean testCase) throws TestCaseFailed
public void checkElementEnable(String accessType, String accessName, boolean testCase)
{
boolean result=isElementEnabled(accessType,accessName);
if(testCase)
{
if (!result)
throw new TestCaseFailed("Element Not Enabled");
fail("Element Not Enabled");
}
else
{
if(result)
throw new TestCaseFailed("Element Enabled");
fail("Element Enabled");
}
}
......@@ -166,18 +169,18 @@ public class AssertionMethods extends SelectElementByType implements BaseTest
@param accessName : String : Locator value
@param testCase : Boolean : test case [true or false]
*/
public void checkElementAttribute(String accessType, String attributeName, String attributeValue, String accessName, boolean testCase) throws TestCaseFailed
public void checkElementAttribute(String accessType, String attributeName, String attributeValue, String accessName, boolean testCase)
{
String attrVal = getElementAttribute(accessType, accessName, attributeName);
if(testCase)
{
if(!attrVal.equals(attributeValue))
throw new TestCaseFailed("Attribute Value Not Matched");
fail("Attribute Value Not Matched");
}
else
{
if(attrVal.equals(attributeValue))
throw new TestCaseFailed("Attribute Value Matched");
fail("Attribute Value Matched");
}
}
......@@ -197,24 +200,30 @@ public class AssertionMethods extends SelectElementByType implements BaseTest
@param accessName : String : Locator value
@param testCase : Boolean : test case [true or false]
*/
public void checkElementPresence(String accessType,String accessName,boolean testCase) throws TestCaseFailed
public void checkElementPresence(String accessType,String accessName,boolean testCase)
{
if (testCase)
{
try{
if (!isElementDisplayed(accessType, accessName))
throw new TestCaseFailed("Element Not Present");
fail("Element with %s '%s' not present.".formatted(accessType, accessName));
}
catch(TimeoutException e) {
fail("Element with %s '%s' not present.".formatted(accessType, accessName));
}
}
else
{
try
{
if(isElementDisplayed(accessType, accessName))
throw new Exception("Present"); //since it is negative test and we found element
fail("Element with %s '%s' present.".formatted(accessType, accessName));
}
catch(Exception e)
{
if(e.getMessage().equals("Present")) //only raise if it present
throw new TestCaseFailed("Element Present");
fail("Element with %s '%s' present.".formatted(accessType, accessName));
}
}
}
......@@ -224,13 +233,13 @@ public class AssertionMethods extends SelectElementByType implements BaseTest
@param accessName : String : Locator value
@param shouldBeChecked : Boolean : test case [true or false]
*/
public void isCheckboxChecked(String accessType,String accessName,boolean shouldBeChecked) throws TestCaseFailed
public void isCheckboxChecked(String accessType,String accessName,boolean shouldBeChecked)
{
WebElement checkbox = wait.until(ExpectedConditions.presenceOfElementLocated(getelementbytype(accessType, accessName)));
if((!checkbox.isSelected()) && shouldBeChecked)
throw new TestCaseFailed("Checkbox is not checked");
fail("Checkbox is not checked");
else if(checkbox.isSelected() && !shouldBeChecked)
throw new TestCaseFailed("Checkbox is checked");
fail("Checkbox is checked");
}
/** method to assert radio button selected/unselected
......@@ -238,17 +247,17 @@ public class AssertionMethods extends SelectElementByType implements BaseTest
@param accessName : String : Locator value
@param shouldBeChecked : Boolean : test case [true or false]
*/
public void isRadioButtonSelected(String accessType,String accessName,boolean shouldBeSelected) throws TestCaseFailed
public void isRadioButtonSelected(String accessType,String accessName,boolean shouldBeSelected)
{
WebElement radioButton = wait.until(ExpectedConditions.presenceOfElementLocated(getelementbytype(accessType, accessName)));
if((!radioButton.isSelected()) && shouldBeSelected)
throw new TestCaseFailed("Radio Button not selected");
fail("Radio Button not selected");
else if(radioButton.isSelected() && !shouldBeSelected)
throw new TestCaseFailed("Radio Button is selected");
fail("Radio Button is selected");
}
//method to assert option from radio button group is selected/unselected
public void isOptionFromRadioButtonGroupSelected(String accessType,String by,String option,String accessName,boolean shouldBeSelected) throws TestCaseFailed
public void isOptionFromRadioButtonGroupSelected(String accessType,String by,String option,String accessName,boolean shouldBeSelected)
{
List<WebElement> radioButtonGroup = wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(getelementbytype(accessType, accessName)));
......@@ -258,17 +267,17 @@ public class AssertionMethods extends SelectElementByType implements BaseTest
if(rb.getAttribute("value").equals(option))
{
if((!rb.isSelected()) && shouldBeSelected)
throw new TestCaseFailed("Radio Button not selected");
fail("Radio Button not selected");
else if(rb.isSelected() && !shouldBeSelected)
throw new TestCaseFailed("Radio Button is selected");
fail("Radio Button is selected");
}
}
else if(rb.getText().equals(option))
{
if((!rb.isSelected()) && shouldBeSelected)
throw new TestCaseFailed("Radio Button not selected");
fail("Radio Button not selected");
else if(rb.isSelected() && !shouldBeSelected)
throw new TestCaseFailed("Radio Button is selected");
fail("Radio Button is selected");
}
}
}
......@@ -283,12 +292,11 @@ public class AssertionMethods extends SelectElementByType implements BaseTest
/**method to check javascript pop-up alert text
* @param text : String : Text to verify in Alert
* @throws TestCaseFailed
*/
public void checkAlertText(String text) throws TestCaseFailed
public void checkAlertText(String text)
{
if(!getAlertText().equals(text))
throw new TestCaseFailed("Text on alert pop up not matched");
fail("Text on alert pop up not matched");
}
/** Method to verify if the particular option is Selected from Dropdown
......@@ -297,9 +305,8 @@ public class AssertionMethods extends SelectElementByType implements BaseTest
* @param option : String : Element to select from dropdown
* @param accessName : String : Locator value
* @param shouldBeSelected : Boolean : test case [true or false]
* @throws TestCaseFailed
*/
public void isOptionFromDropdownSelected(String accessType,String by,String option,String accessName,boolean shouldBeSelected) throws TestCaseFailed
public void isOptionFromDropdownSelected(String accessType,String by,String option,String accessName,boolean shouldBeSelected)
{
Select selectList=null;
WebElement dropdown = wait.until(ExpectedConditions.presenceOfElementLocated(getelementbytype(accessType, accessName)));
......@@ -312,8 +319,8 @@ public class AssertionMethods extends SelectElementByType implements BaseTest
actualValue = selectList.getFirstSelectedOption().getAttribute("value");
if((!actualValue.equals(option))&&(shouldBeSelected))
throw new TestCaseFailed("Option Not Selected From Dropwdown");
fail("Option Not Selected From Dropwdown");
else if ((actualValue.equals(option))&&(!shouldBeSelected))
throw new TestCaseFailed("Option Selected From Dropwdown");
fail("Option Selected From Dropwdown");
}
}
......@@ -13,7 +13,7 @@ public class SelectElementByType
protected WebDriverWait wait;
public SelectElementByType() {
driver = DriverUtil.getDefaultDriver();
wait = new WebDriverWait(driver, Duration.ofSeconds(30));
wait = new WebDriverWait(driver, Duration.ofSeconds(10));
}
/**Method to select element 'by' type
* @param type : String : 'By' type
......
package fr.univlille.gitlab.sra12023.cucumberrunner.selenium;
public class TestCaseFailed extends Exception
{
/**
* Added serializable varibale to remove warning
*/
private static final long serialVersionUID = 1L;
String message=null;
public TestCaseFailed()
{
super();
}
public TestCaseFailed(String message)
{
super(message);
this.message = message;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment