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

:art: : format code

parent f130f49f
Branches
No related tags found
No related merge requests found
Showing
with 862 additions and 848 deletions
......@@ -9,232 +9,219 @@ import java.util.List;
import static org.assertj.core.api.Assertions.fail;
public class AssertionMethods extends SelectElementByType implements BaseTest
{
public class AssertionMethods extends SelectElementByType implements BaseTest {
//This file contains assertion methods which are called from predefinedStepDefinitions
//SelectElementByType eleType= new SelectElementByType();
private WebElement element = null;
/** Method to get page title
/**
* Method to get page title
*
* @return String
* */
public String getPageTitle()
{
*/
public String getPageTitle() {
return driver.getTitle();
}
/** Method to verify page title
/**
* Method to verify page title
*
* @param title : String : expected title
* @param testCase : Boolean : test case [true or false]
*/
public void checkTitle(String title,boolean testCase)
{
public void checkTitle(String title, boolean testCase) {
String pageTitle = getPageTitle();
if(testCase)
{
if (testCase) {
if (!pageTitle.equals(title))
fail("Page Title Not Matched, Actual Page Title : " + pageTitle);
}
else
{
} else {
if (pageTitle.equals(title))
fail("Page Title Matched, Actual Page Title : " + pageTitle);
}
}
/** Method to verify partial page title
/**
* Method to verify partial page title
*
* @param partialTitle : String : partial title string
* @param testCase : Boolean : test case [true or false]
*/
public void checkPartialTitle(String partialTitle,boolean testCase)
{
public void checkPartialTitle(String partialTitle, boolean testCase) {
String pageTitle = getPageTitle();
if(testCase)
{
if (testCase) {
if (!pageTitle.contains(partialTitle))
fail("Partial Page Title Not Present, Actual Page Title : " + pageTitle);
}
else
{
} else {
if (pageTitle.contains(partialTitle))
fail("Partial Page Title Present, Actual Page Title : " + pageTitle);
}
}
/** Method to get element text
/**
* Method to get element text
*
* @param accessType : String : Locator type (id, name, class, xpath, css)
* @param accessName : String : Locator value
* @return String
*/
public String getElementText(String accessType, String accessName)
{
public String getElementText(String accessType, String accessName) {
element = wait.until(ExpectedConditions.presenceOfElementLocated(getelementbytype(accessType, accessName)));
return element.getText();
}
/** Method to check element text
/**
* Method to check element text
*
* @param accessType : String : Locator type (id, name, class, xpath, css)
* @param actualValue : String : Expected element text
* @param accessName : String : Locator value
* @param testCase : Boolean : test case [true or false]
*/
public void checkElementText(String accessType,String actualValue,String accessName,boolean testCase)
{
public void checkElementText(String accessType, String actualValue, String accessName, boolean testCase) {
String elementText = getElementText(accessType, accessName);
if (testCase)
{
if (testCase) {
if (!elementText.equals(actualValue))
fail("Text Not Matched");
}
else
{
} else {
if (elementText.equals(actualValue))
fail("Text Matched");
}
}
/** Method to check partial element text
/**
* Method to check partial element text
*
* @param accessType : String : Locator type (id, name, class, xpath, css)
* @param actualValue : String : Expected element text
* @param accessName : String : Locator value
* @param testCase : Boolean : test case [true or false]
*/
public void checkElementPartialText(String accessType,String actualValue,String accessName,boolean testCase)
{
public void checkElementPartialText(String accessType, String actualValue, String accessName, boolean testCase) {
String elementText = getElementText(accessType, accessName);
if (testCase)
{
if (testCase) {
if (!elementText.contains(actualValue))
fail("Text Not Matched");
}
else
{
} else {
if (elementText.contains(actualValue))
fail("Text Matched");
}
}
/** Method to return element status - enabled?
/**
* Method to return element status - enabled?
*
* @param accessType : String : Locator type (id, name, class, xpath, css)
* @param accessName : String : Locator value
* @return Boolean
*/
public boolean isElementEnabled(String accessType, String accessName)
{
public boolean isElementEnabled(String accessType, String accessName) {
element = wait.until(ExpectedConditions.presenceOfElementLocated(getelementbytype(accessType, accessName)));
return element.isEnabled();
}
/** Element enabled checking
@param accessType : String : Locator type (id, name, class, xpath, css)
@param accessName : String : Locator value
@param testCase : Boolean : test case [true or false]
/**
* Element enabled checking
*
* @param accessType : String : Locator type (id, name, class, xpath, css)
* @param accessName : String : Locator value
* @param testCase : Boolean : test case [true or false]
*/
public void checkElementEnable(String accessType, String accessName, boolean testCase)
{
public void checkElementEnable(String accessType, String accessName, boolean testCase) {
boolean result = isElementEnabled(accessType, accessName);
if(testCase)
{
if (testCase) {
if (!result)
fail("Element Not Enabled");
}
else
{
} else {
if (result)
fail("Element Enabled");
}
}
/** method to get attribute value
@param accessType : String : Locator type (id, name, class, xpath, css)
@param accessName : String : Locator value
@param attributeName : String : attribute name
@return String
/**
* method to get attribute value
*
* @param accessType : String : Locator type (id, name, class, xpath, css)
* @param accessName : String : Locator value
* @param attributeName : String : attribute name
* @return String
*/
public String getElementAttribute(String accessType,String accessName,String attributeName)
{
public String getElementAttribute(String accessType, String accessName, String attributeName) {
element = wait.until(ExpectedConditions.presenceOfElementLocated(getelementbytype(accessType, accessName)));
return element.getAttribute(attributeName);
}
/** method to check attribute value
@param accessType : String : Locator type (id, name, class, xpath, css)
@param attributeName : String : attribute name
@param attributeValue : String : attribute value
@param accessName : String : Locator value
@param testCase : Boolean : test case [true or false]
/**
* method to check attribute value
*
* @param accessType : String : Locator type (id, name, class, xpath, css)
* @param attributeName : String : attribute name
* @param attributeValue : String : attribute value
* @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)
{
public void checkElementAttribute(String accessType, String attributeName, String attributeValue, String accessName, boolean testCase) {
String attrVal = getElementAttribute(accessType, accessName, attributeName);
if(testCase)
{
if (testCase) {
if (!attrVal.equals(attributeValue))
fail("Attribute Value Not Matched");
}
else
{
} else {
if (attrVal.equals(attributeValue))
fail("Attribute Value Matched");
}
}
/** method to get element status - displayed?
@param accessType : String : Locator type (id, name, class, xpath, css)
@param accessName : String : Locator value
@return Boolean
/**
* method to get element status - displayed?
*
* @param accessType : String : Locator type (id, name, class, xpath, css)
* @param accessName : String : Locator value
* @return Boolean
*/
public boolean isElementDisplayed(String accessType,String accessName)
{
public boolean isElementDisplayed(String accessType, String accessName) {
element = wait.until(ExpectedConditions.presenceOfElementLocated(getelementbytype(accessType, accessName)));
return element.isDisplayed();
}
/** method to check element presence
@param accessType : String : Locator type (id, name, class, xpath, css)
@param accessName : String : Locator value
@param testCase : Boolean : test case [true or false]
/**
* method to check element presence
*
* @param accessType : String : Locator type (id, name, class, xpath, css)
* @param accessName : String : Locator value
* @param testCase : Boolean : test case [true or false]
*/
public void checkElementPresence(String accessType,String accessName,boolean testCase)
{
if (testCase)
{
public void checkElementPresence(String accessType, String accessName, boolean testCase) {
if (testCase) {
try {
if (!isElementDisplayed(accessType, accessName))
fail("Element with %s '%s' not present.".formatted(accessType, accessName));
}
catch(TimeoutException e) {
} catch (TimeoutException e) {
fail("Element with %s '%s' not present.".formatted(accessType, accessName));
}
}
else
{
try
{
} else {
try {
if (isElementDisplayed(accessType, accessName))
fail("Element with %s '%s' present.".formatted(accessType, accessName));
}
catch(Exception e)
{
} catch (Exception e) {
if (e.getMessage().equals("Present")) //only raise if it present
fail("Element with %s '%s' present.".formatted(accessType, accessName));
}
}
}
/** method to assert checkbox check/uncheck
@param accessType : String : Locator type (id, name, class, xpath, css)
@param accessName : String : Locator value
@param shouldBeChecked : Boolean : test case [true or false]
/**
* method to assert checkbox check/uncheck
*
* @param accessType : String : Locator type (id, name, class, xpath, css)
* @param accessName : String : Locator value
* @param shouldBeChecked : Boolean : test case [true or false]
*/
public void isCheckboxChecked(String accessType,String accessName,boolean shouldBeChecked)
{
public void isCheckboxChecked(String accessType, String accessName, boolean shouldBeChecked) {
WebElement checkbox = wait.until(ExpectedConditions.presenceOfElementLocated(getelementbytype(accessType, accessName)));
if ((!checkbox.isSelected()) && shouldBeChecked)
fail("Checkbox is not checked");
......@@ -242,13 +229,14 @@ public class AssertionMethods extends SelectElementByType implements BaseTest
fail("Checkbox is checked");
}
/** method to assert radio button selected/unselected
@param accessType : String : Locator type (id, name, class, xpath, css)
@param accessName : String : Locator value
@param shouldBeChecked : Boolean : test case [true or false]
/**
* method to assert radio button selected/unselected
*
* @param accessType : String : Locator type (id, name, class, xpath, css)
* @param accessName : String : Locator value
* @param shouldBeChecked : Boolean : test case [true or false]
*/
public void isRadioButtonSelected(String accessType,String accessName,boolean shouldBeSelected)
{
public void isRadioButtonSelected(String accessType, String accessName, boolean shouldBeSelected) {
WebElement radioButton = wait.until(ExpectedConditions.presenceOfElementLocated(getelementbytype(accessType, accessName)));
if ((!radioButton.isSelected()) && shouldBeSelected)
fail("Radio Button not selected");
......@@ -257,23 +245,18 @@ public class AssertionMethods extends SelectElementByType implements BaseTest
}
//method to assert option from radio button group is selected/unselected
public void isOptionFromRadioButtonGroupSelected(String accessType,String by,String option,String accessName,boolean shouldBeSelected)
{
public void isOptionFromRadioButtonGroupSelected(String accessType, String by, String option, String accessName, boolean shouldBeSelected) {
List<WebElement> radioButtonGroup = wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(getelementbytype(accessType, accessName)));
for (WebElement rb : radioButtonGroup) {
if(by.equals("value"))
{
if(rb.getAttribute("value").equals(option))
{
if (by.equals("value")) {
if (rb.getAttribute("value").equals(option)) {
if ((!rb.isSelected()) && shouldBeSelected)
fail("Radio Button not selected");
else if (rb.isSelected() && !shouldBeSelected)
fail("Radio Button is selected");
}
}
else if(rb.getText().equals(option))
{
} else if (rb.getText().equals(option)) {
if ((!rb.isSelected()) && shouldBeSelected)
fail("Radio Button not selected");
else if (rb.isSelected() && !shouldBeSelected)
......@@ -282,32 +265,35 @@ public class AssertionMethods extends SelectElementByType implements BaseTest
}
}
/** method to get javascript pop-up alert text
/**
* method to get javascript pop-up alert text
*
* @return String
*/
public String getAlertText()
{
public String getAlertText() {
return driver.switchTo().alert().getText();
}
/**method to check javascript pop-up alert text
/**
* method to check javascript pop-up alert text
*
* @param text : String : Text to verify in Alert
*/
public void checkAlertText(String text)
{
public void checkAlertText(String text) {
if (!getAlertText().equals(text))
fail("Text on alert pop up not matched");
}
/** Method to verify if the particular option is Selected from Dropdown
/**
* Method to verify if the particular option is Selected from Dropdown
*
* @param accessType : String : Locator type (id, name, class, xpath, css)
* @param by : String : Select element from dropdown by text or value
* @param option : String : Element to select from dropdown
* @param accessName : String : Locator value
* @param shouldBeSelected : Boolean : test case [true or false]
*/
public void isOptionFromDropdownSelected(String accessType,String by,String option,String accessName,boolean shouldBeSelected)
{
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)));
selectList = new Select(dropdown);
......
package fr.univlille.gitlab.sra12023.cucumberrunner.selenium;
public interface BaseTest
{
public interface BaseTest {
MiscMethods miscmethodObj = new MiscMethods();
NavigateMethods navigationObj = new NavigateMethods();
AssertionMethods assertionObj = new AssertionMethods();
......
......@@ -6,38 +6,40 @@ import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
public class ClickElementsMethods extends SelectElementByType implements BaseTest
{
public class ClickElementsMethods extends SelectElementByType implements BaseTest {
//SelectElementByType eleType= new SelectElementByType();
private WebElement element = null;
/** Method to click on an element
@param accessType : String : Locator type (id, name, class, xpath, css)
@param accessName : String : Locator value
/**
* Method to click on an element
*
* @param accessType : String : Locator type (id, name, class, xpath, css)
* @param accessName : String : Locator value
*/
public void click(String accessType, String accessName)
{
public void click(String accessType, String accessName) {
element = wait.until(ExpectedConditions.presenceOfElementLocated(getelementbytype(accessType, accessName)));
element.click();
}
/** Method to forcefully click on an element
@param accessType : String : Locator type (id, name, class, xpath, css)
@param accessName : String : Locator value
/**
* Method to forcefully click on an element
*
* @param accessType : String : Locator type (id, name, class, xpath, css)
* @param accessName : String : Locator value
*/
public void clickForcefully(String accessType, String accessName)
{
public void clickForcefully(String accessType, String accessName) {
element = wait.until(ExpectedConditions.presenceOfElementLocated(getelementbytype(accessType, accessName)));
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", element);
}
/** Method to Double click on an element
@param accessType : String : Locator type (id, name, class, xpath, css)
@param accessName : String : Locator value
/**
* Method to Double click on an element
*
* @param accessType : String : Locator type (id, name, class, xpath, css)
* @param accessName : String : Locator value
*/
public void doubleClick(String accessType, String accessValue)
{
public void doubleClick(String accessType, String accessValue) {
element = wait.until(ExpectedConditions.presenceOfElementLocated(getelementbytype(accessType, accessValue)));
Actions action = new Actions(driver);
......
......@@ -9,15 +9,17 @@ import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class ConfigurationMethods implements BaseTest
{
public class ConfigurationMethods implements BaseTest {
protected WebDriver driver;
public ConfigurationMethods() {
driver = DriverUtil.getDefaultDriver();
}
/** Method to print desktop configuration */
public void printDesktopConfiguration()
{
/**
* Method to print desktop configuration
*/
public void printDesktopConfiguration() {
DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
Calendar cal = Calendar.getInstance();
......
......@@ -2,17 +2,13 @@ package fr.univlille.gitlab.sra12023.cucumberrunner.selenium;
import java.util.Arrays;
public class ErrorHandlingMethods
{
public class ErrorHandlingMethods {
//Method to check browser type
public void validateParameters(String platform, String browserType, String appPath)
{
if(platform.equals("desktop"))
{
public void validateParameters(String platform, String browserType, String appPath) {
if (platform.equals("desktop")) {
if (Arrays.asList("ff", "ie", "chrome", "safari", "opera").contains(browserType))
printErrorDesktop();
}
else if(platform.equals("android"))
} else if (platform.equals("android"))
printErrorAndroid(browserType, appPath);
else if (platform.equals("iOS"))
System.out.println("Not Implemented...");
......@@ -21,8 +17,7 @@ public class ErrorHandlingMethods
}
//print error for desktop
private void printErrorDesktop()
{
private void printErrorDesktop() {
System.out.println("\nInappropraite desktop browser : \"#{ENV['BROWSER']}\"");
System.out.println("\nUsage : cucumber BROWSER=browser_name");
System.out.println("\nBrowser Supported :\n");
......@@ -31,8 +26,7 @@ public class ErrorHandlingMethods
}
//print error for android
public void printErrorAndroid(String browserType,String appPath)
{
public void printErrorAndroid(String browserType, String appPath) {
/*if browser_type=='ff' and app_path==nil
puts "\nOops... not mentioned \"Browser\" or \"App path\""
print_error_android_app
......@@ -47,8 +41,7 @@ public class ErrorHandlingMethods
}
//print error if invalid platform
public void printInvalidPlatform()
{
public void printInvalidPlatform() {
System.out.println("\nOops... Invalid Platform");
System.out.println("\nSupported platform are \"android\" and \"iOS\".");
System.out.println("\nTo run on Desktop no need to mention platform.");
......
......@@ -7,59 +7,60 @@ import org.openqa.selenium.support.ui.Select;
import java.util.List;
public class InputMethods extends SelectElementByType implements BaseTest
{
public class InputMethods extends SelectElementByType implements BaseTest {
//SelectElementByType eleType= new SelectElementByType();
private WebElement dropdown = null;
private Select selectList = null;
/** Method to enter text into text field
/**
* Method to enter text into text field
*
* @param accessType : String : Locator type (id, name, class, xpath, css)
* @param text : String : Text value to enter in field
@param accessName : String : Locator value
* @param accessName : String : Locator value
*/
public void enterText(String accessType,String text,String accessName)
{
public void enterText(String accessType, String text, String accessName) {
wait.until(ExpectedConditions.presenceOfElementLocated(getelementbytype(accessType, accessName)));
driver.findElement(getelementbytype(accessType, accessName)).sendKeys(text);
}
/** Method to clear text of text field
@param accessType : String : Locator type (id, name, class, xpath, css)
@param accessName : String : Locator value
/**
* Method to clear text of text field
*
* @param accessType : String : Locator type (id, name, class, xpath, css)
* @param accessName : String : Locator value
*/
public void clearText(String accessType, String accessName)
{
public void clearText(String accessType, String accessName) {
wait.until(ExpectedConditions.presenceOfElementLocated(getelementbytype(accessType, accessName)));
driver.findElement(getelementbytype(accessType, accessName)).clear();
}
/** Method to select element from Dropdown by type
/**
* Method to select element from Dropdown by type
*
* @param select_list : Select : Select variable
* @param bytype : String : Name of by type
* @param option : String : Option to select
*/
public void selectelementfromdropdownbytype (Select select_list, String bytype, String option)
{
if(bytype.equals("selectByIndex"))
{
public void selectelementfromdropdownbytype(Select select_list, String bytype, String option) {
if (bytype.equals("selectByIndex")) {
int index = Integer.parseInt(option);
select_list.selectByIndex(index - 1);
}
else if (bytype.equals("value"))
} else if (bytype.equals("value"))
select_list.selectByValue(option);
else if (bytype.equals("text"))
select_list.selectByVisibleText(option);
}
/** Method to select option from dropdown list
@param accessType : String : Locator type (id, name, class, xpath, css)
@param by : String : Name of by type
@param option : String : Option to select
@param accessName : String : Locator value
/**
* Method to select option from dropdown list
*
* @param accessType : String : Locator type (id, name, class, xpath, css)
* @param by : String : Name of by type
* @param option : String : Option to select
* @param accessName : String : Locator value
*/
public void selectOptionFromDropdown(String accessType, String optionBy, String option, String accessName)
{
public void selectOptionFromDropdown(String accessType, String optionBy, String option, String accessName) {
dropdown = wait.until(ExpectedConditions.presenceOfElementLocated(getelementbytype(accessType, accessName)));
selectList = new Select(dropdown);
......@@ -80,23 +81,25 @@ public class InputMethods extends SelectElementByType implements BaseTest
// //Select all method not present in JAVA
// }
/** Method to unselect all option from dropdwon list
@param accessType : String : Locator type (id, name, class, xpath, css)
@param accessName : String : Locator value
/**
* Method to unselect all option from dropdwon list
*
* @param accessType : String : Locator type (id, name, class, xpath, css)
* @param accessName : String : Locator value
*/
public void unselectAllOptionFromMultiselectDropdown(String accessType, String accessName)
{
public void unselectAllOptionFromMultiselectDropdown(String accessType, String accessName) {
dropdown = wait.until(ExpectedConditions.presenceOfElementLocated(getelementbytype(accessType, accessName)));
selectList = new Select(dropdown);
selectList.deselectAll();
}
/** Method to unselect option from dropdwon list
@param accessType : String : Locator type (id, name, class, xpath, css)
@param accessName : String : Locator value
/**
* Method to unselect option from dropdwon list
*
* @param accessType : String : Locator type (id, name, class, xpath, css)
* @param accessName : String : Locator value
*/
public void deselectOptionFromDropdown(String accessType, String optionBy, String option, String accessName)
{
public void deselectOptionFromDropdown(String accessType, String optionBy, String option, String accessName) {
dropdown = wait.until(ExpectedConditions.presenceOfElementLocated(getelementbytype(accessType, accessName)));
selectList = new Select(dropdown);
......@@ -108,67 +111,68 @@ public class InputMethods extends SelectElementByType implements BaseTest
selectList.deselectByVisibleText(option);
}
/** Method to check check-box
@param accessType : String : Locator type (id, name, class, xpath, css)
@param accessName : String : Locator value
/**
* Method to check check-box
*
* @param accessType : String : Locator type (id, name, class, xpath, css)
* @param accessName : String : Locator value
*/
public void checkCheckbox(String accessType, String accessName)
{
public void checkCheckbox(String accessType, String accessName) {
WebElement checkbox = wait.until(ExpectedConditions.presenceOfElementLocated(getelementbytype(accessType, accessName)));
if (!checkbox.isSelected())
checkbox.click();
}
/** Method to uncheck check-box
@param accessType : String : Locator type (id, name, class, xpath, css)
@param accessName : String : Locator value
/**
* Method to uncheck check-box
*
* @param accessType : String : Locator type (id, name, class, xpath, css)
* @param accessName : String : Locator value
*/
public void uncheckCheckbox(String accessType, String accessName)
{
public void uncheckCheckbox(String accessType, String accessName) {
WebElement checkbox = wait.until(ExpectedConditions.presenceOfElementLocated(getelementbytype(accessType, accessName)));
if (checkbox.isSelected())
checkbox.click();
}
/** Method to toggle check-box status
@param accessType : String : Locator type (id, name, class, xpath, css)
@param accessName : String : Locator value
/**
* Method to toggle check-box status
*
* @param accessType : String : Locator type (id, name, class, xpath, css)
* @param accessName : String : Locator value
*/
public void toggleCheckbox(String accessType, String accessName)
{
public void toggleCheckbox(String accessType, String accessName) {
wait.until(ExpectedConditions.presenceOfElementLocated(getelementbytype(accessType, accessName))).click();
}
/** Method to select radio button
@param accessType : String : Locator type (id, name, class, xpath, css)
@param accessName : String : Locator value
/**
* Method to select radio button
*
* @param accessType : String : Locator type (id, name, class, xpath, css)
* @param accessName : String : Locator value
*/
public void selectRadioButton(String accessType, String accessName)
{
public void selectRadioButton(String accessType, String accessName) {
WebElement radioButton = wait.until(ExpectedConditions.presenceOfElementLocated(getelementbytype(accessType, accessName)));
if (!radioButton.isSelected())
radioButton.click();
}
/** Method to select option from radio button group
@param accessType : String : Locator type (id, name, class, xpath, css)
@param by : String : Name of by type
@param option : String : Option to select
@param accessName : String : Locator value
/**
* Method to select option from radio button group
*
* @param accessType : String : Locator type (id, name, class, xpath, css)
* @param by : String : Name of by type
* @param option : String : Option to select
* @param accessName : String : Locator value
* @param accessName2
*/
public void selectOptionFromRadioButtonGroup(String accessType, String option, String by, String accessName)
{
public void selectOptionFromRadioButtonGroup(String accessType, String option, String by, String accessName) {
List<WebElement> radioButtonGroup = driver.findElements(getelementbytype(accessType, accessName));
for(WebElement rb : radioButtonGroup)
{
if(by.equals("value"))
{
for (WebElement rb : radioButtonGroup) {
if (by.equals("value")) {
if (rb.getAttribute("value").equals(option) && !rb.isSelected())
rb.click();
}
else if(by.equals("text"))
{
} else if (by.equals("text")) {
if (rb.getText().equals(option) && !rb.isSelected())
rb.click();
}
......
......@@ -5,11 +5,13 @@ import org.openqa.selenium.WebDriver;
public class JavascriptHandlingMethods implements BaseTest {
protected WebDriver driver = DriverUtil.getDefaultDriver();
/**Method to handle alert
/**
* Method to handle alert
*
* @param decision : String : Accept or dismiss alert
*/
public void handleAlert(String decision)
{
public void handleAlert(String decision) {
if (decision.equals("accept"))
driver.switchTo().alert().accept();
else
......
......@@ -2,33 +2,32 @@ package fr.univlille.gitlab.sra12023.cucumberrunner.selenium;
import java.util.Arrays;
public class MiscMethods
{
public boolean valid_locator_type(String type)
{
public class MiscMethods {
public boolean valid_locator_type(String type) {
return Arrays.asList("id", "class", "css", "name", "xpath").contains(type);
}
/** Method to verify locator type
/**
* Method to verify locator type
*
* @param type : String : Locator type (id, name, class, xpath, css)
*/
public void validateLocator(String type) throws Exception
{
public void validateLocator(String type) throws Exception {
if (!valid_locator_type(type))
throw new Exception("Invalid locator type - " + type);
}
// method to validate dropdown selector
public boolean valid_option_by(String option_by)
{
public boolean valid_option_by(String option_by) {
return Arrays.asList("text", "value", "index").contains(option_by);
}
/** Method to verify dropdown selector (text, value or index)
/**
* Method to verify dropdown selector (text, value or index)
*
* @param optionBy : String : Locator type (text, value, index)
*/
public void validateOptionBy(String optionBy) throws Exception
{
public void validateOptionBy(String optionBy) throws Exception {
if (!valid_option_by(optionBy))
throw new Exception("Invalid option by - " + optionBy);
}
......
......@@ -8,43 +8,46 @@ import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
public class NavigateMethods extends SelectElementByType implements BaseTest
{
public class NavigateMethods extends SelectElementByType implements BaseTest {
//SelectElementByType eleType= new SelectElementByType();
private WebElement element = null;
private String old_win = null;
private String lastWinHandle;
/** Method to open link
/**
* Method to open link
*
* @param url : String : URL for navigation
*/
public void navigateTo(String url)
{
public void navigateTo(String url) {
driver.get(url);
}
/** Method to navigate back & forward
/**
* Method to navigate back & forward
*
* @param direction : String : Navigate to forward or backward
*/
public void navigate(String direction)
{
public void navigate(String direction) {
if (direction.equals("back"))
driver.navigate().back();
else
driver.navigate().forward();
}
/** Method to quite webdriver instance */
public void closeDriver()
{
/**
* Method to quite webdriver instance
*/
public void closeDriver() {
driver.close();
}
/** Method to return key by OS wise
/**
* Method to return key by OS wise
*
* @return Keys : Return control or command key as per OS
*/
public Keys getKey()
{
public Keys getKey() {
String os = System.getProperty("os.name").toLowerCase();
if (os.contains("win"))
return Keys.CONTROL;
......@@ -56,11 +59,12 @@ public class NavigateMethods extends SelectElementByType implements BaseTest
return null;
}
/** Method to zoom in/out page
/**
* Method to zoom in/out page
*
* @param inOut : String : Zoom in or out
*/
public void zoomInOut(String inOut)
{
public void zoomInOut(String inOut) {
WebElement Sel = driver.findElement(getelementbytype("tagName", "html"));
if (inOut.equals("ADD"))
Sel.sendKeys(Keys.chord(getKey(), Keys.ADD));
......@@ -70,17 +74,17 @@ public class NavigateMethods extends SelectElementByType implements BaseTest
Sel.sendKeys(Keys.chord(getKey(), Keys.NUMPAD0));
}
/** Method to zoom in/out web page until web element displays
/**
* Method to zoom in/out web page until web element displays
*
* @param accessType : String : Locator type (id, name, class, xpath, css)
* @param inOut : String : Zoom in or out
* @param accessName : String : Locator value
*/
public void zoomInOutTillElementDisplay(String accessType,String inOut,String accessName)
{
public void zoomInOutTillElementDisplay(String accessType, String inOut, String accessName) {
Actions action = new Actions(driver);
element = wait.until(ExpectedConditions.presenceOfElementLocated(getelementbytype(accessType, accessName)));
while(true)
{
while (true) {
if (element.isDisplayed())
break;
else
......@@ -88,49 +92,54 @@ public class NavigateMethods extends SelectElementByType implements BaseTest
}
}
/** Method to resize browser
/**
* Method to resize browser
*
* @param width : int : Width for browser resize
* @param height : int : Height for browser resize
*/
public void resizeBrowser(int width, int height)
{
public void resizeBrowser(int width, int height) {
driver.manage().window().setSize(new Dimension(width, height));
}
/** Method to maximize browser */
public void maximizeBrowser()
{
/**
* Method to maximize browser
*/
public void maximizeBrowser() {
driver.manage().window().maximize();
}
/** Method to hover on element
/**
* Method to hover on element
*
* @param accessType : String : Locator type (id, name, class, xpath, css)
* @param accessName : String : Locator value
*/
public void hoverOverElement(String accessType, String accessName)
{
public void hoverOverElement(String accessType, String accessName) {
Actions action = new Actions(driver);
element = wait.until(ExpectedConditions.presenceOfElementLocated(getelementbytype(accessType, accessName)));
action.moveToElement(element).perform();
}
/** Method to scroll page to particular element
/**
* Method to scroll page to particular element
*
* @param accessType : String : Locator type (id, name, class, xpath, css)
* @param accessName : String : Locator value
*/
public void scrollToElement(String accessType, String accessName)
{
public void scrollToElement(String accessType, String accessName) {
element = wait.until(ExpectedConditions.presenceOfElementLocated(getelementbytype(accessType, accessName)));
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].scrollIntoView();", element);
}
/** Method to scroll page to top or end
/**
* Method to scroll page to top or end
*
* @param to : String : Scroll page to Top or End
* @throws Exception
*/
public void scrollPage(String to) throws Exception
{
public void scrollPage(String to) throws Exception {
JavascriptExecutor executor = (JavascriptExecutor) driver;
if (to.equals("end"))
executor.executeScript("window.scrollTo(0,Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,document.documentElement.clientHeight));");
......@@ -140,35 +149,37 @@ public class NavigateMethods extends SelectElementByType implements BaseTest
throw new Exception("Exception : Invalid Direction (only scroll \"top\" or \"end\")");
}
/**Method to switch to new window */
public void switchToNewWindow()
{
/**
* Method to switch to new window
*/
public void switchToNewWindow() {
old_win = driver.getWindowHandle();
for (String winHandle : driver.getWindowHandles())
lastWinHandle = winHandle;
driver.switchTo().window(lastWinHandle);
}
/** Method to switch to old window */
public void switchToOldWindow()
{
/**
* Method to switch to old window
*/
public void switchToOldWindow() {
driver.switchTo().window(old_win);
}
/** Method to switch to window by title
/**
* Method to switch to window by title
*
* @param windowTitle : String : Name of window title to switch
* @throws Exception */
public void switchToWindowByTitle(String windowTitle) throws Exception
{
* @throws Exception
*/
public void switchToWindowByTitle(String windowTitle) throws Exception {
//System.out.println("++"+windowTitle+"++");
old_win = driver.getWindowHandle();
boolean winFound = false;
for(String winHandle : driver.getWindowHandles())
{
for (String winHandle : driver.getWindowHandles()) {
String str = driver.switchTo().window(winHandle).getTitle();
//System.out.println("**"+str+"**");
if (str.equals(windowTitle))
{
if (str.equals(windowTitle)) {
winFound = true;
break;
}
......@@ -177,30 +188,32 @@ public class NavigateMethods extends SelectElementByType implements BaseTest
throw new Exception("Window having title " + windowTitle + " not found");
}
/**Method to close new window*/
public void closeNewWindow()
{
/**
* Method to close new window
*/
public void closeNewWindow() {
driver.close();
}
/** Method to switch frame using web element frame
/**
* Method to switch frame using web element frame
*
* @param accessType : String : Locator type (index, id, name, class, xpath, css)
* @param accessName : String : Locator value
* */
public void switchFrame(String accessType, String accessName)
{
*/
public void switchFrame(String accessType, String accessName) {
if (accessType.equalsIgnoreCase("index"))
driver.switchTo().frame(accessName);
else
{
else {
element = wait.until(ExpectedConditions.presenceOfElementLocated(getelementbytype(accessType, accessName)));
driver.switchTo().frame(element);
}
}
/** method to switch to default content*/
public void switchToDefaultContent()
{
/**
* method to switch to default content
*/
public void switchToDefaultContent() {
driver.switchTo().defaultContent();
}
}
......@@ -7,39 +7,41 @@ import org.openqa.selenium.support.ui.WebDriverWait;
import java.time.Duration;
public class ProgressMethods extends SelectElementByType implements BaseTest
{
/** Method to wait
public class ProgressMethods extends SelectElementByType implements BaseTest {
/**
* Method to wait
*
* @param time : String : Time to wait
* @param method : String : wait by sleep or implicit method
* @throws NumberFormatException
* @throws InterruptedException
*/
public void wait(String time) throws NumberFormatException, InterruptedException
{
public void wait(String time) throws NumberFormatException, InterruptedException {
//sleep method takes parameter in milliseconds
Thread.sleep(Integer.parseInt(time) * 1000);
}
/**Method to Explicitly wait for element to be displayed
/**
* Method to Explicitly wait for element to be displayed
*
* @param accessType : String : Locator type (id, name, class, xpath, css)
* @param accessName : String : Locator value
* @param duration : String : Time to wait for element to be displayed
*/
public void waitForElementToDisplay(String accessType,String accessName,String duration)
{
public void waitForElementToDisplay(String accessType, String accessName, String duration) {
By byEle = getelementbytype(accessType, accessName);
WebDriverWait wait = new WebDriverWait(driver, Duration.ofMillis(Long.parseLong(duration)));
wait.until(ExpectedConditions.visibilityOfElementLocated(byEle));
}
/** Method to Explicitly wait for element to be enabled=click
/**
* Method to Explicitly wait for element to be enabled=click
*
* @param accessType : String : Locator type (id, name, class, xpath, css)
* @param accessName : String : Locator value
* @param duration : String : Time to wait for element to be clickable
*/
public void waitForElementToClick(String accessType,String accessName,String duration)
{
public void waitForElementToClick(String accessType, String accessName, String duration) {
By byEle = getelementbytype(accessType, accessName);
WebDriverWait wait = new WebDriverWait(driver, Duration.ofMillis(Long.parseLong(duration)));
wait.until(ExpectedConditions.elementToBeClickable(byEle));
......
......@@ -15,9 +15,11 @@ import java.util.Calendar;
public class ScreenShotMethods implements BaseTest {
protected WebDriver driver = DriverUtil.getDefaultDriver();
/** Method to take screen shot and save in ./Screenshots folder*/
public void takeScreenShot() throws IOException
{
/**
* Method to take screen shot and save in ./Screenshots folder
*/
public void takeScreenShot() throws IOException {
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
......
......@@ -7,32 +7,42 @@ import org.openqa.selenium.support.ui.WebDriverWait;
import java.time.Duration;
public class SelectElementByType
{
public class SelectElementByType {
protected WebDriver driver;
protected WebDriverWait wait;
public SelectElementByType() {
driver = DriverUtil.getDefaultDriver();
wait = new WebDriverWait(driver, Duration.ofSeconds(10));
}
/**Method to select element 'by' type
/**
* Method to select element 'by' type
*
* @param type : String : 'By' type
* @param access_name : String : Locator value
* @return By
*/
public By getelementbytype(String type,String access_name)
{
switch(type)
{
case "id" : return By.id(access_name);
case "name" : return By.name(access_name);
case "class" : return By.className(access_name);
case "xpath" : return By.xpath(access_name);
case "css" : return By.cssSelector(access_name);
case "linkText" : return By.linkText(access_name);
case "partialLinkText" : return By.partialLinkText(access_name);
case "tagName" : return By.tagName(access_name);
default : return null;
public By getelementbytype(String type, String access_name) {
switch (type) {
case "id":
return By.id(access_name);
case "name":
return By.name(access_name);
case "class":
return By.className(access_name);
case "xpath":
return By.xpath(access_name);
case "css":
return By.cssSelector(access_name);
case "linkText":
return By.linkText(access_name);
case "partialLinkText":
return By.partialLinkText(access_name);
case "tagName":
return By.tagName(access_name);
default:
return null;
}
/*if(type.equals("id"))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment