Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
{
WebDriverWait wait = new WebDriverWait(driver,waitTime);
WebElement element=null;
try
{
// elementToBeClickable is used for checking an element is visible and enabled such that you can click it
element=wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
System.out.println("element found");
}
catch (Exception e) {
e.printStackTrace();
String message = "Timeout waiting for the element "+ locator +", after "+waitTime+" seconds.";
log.info(message);
log.info(e.getMessage());
DriverScript.bResult = "fail";
DriverScript.eMessage = message;
}
return element;
}
public void input_and_select_optionalField( final HashMap<String,String> stepDetails, Map<String,String> testData) throws MyException,Exception
{
String value=testData.get(stepDetails.get("Field Name"));
if (value.equals("")|| value.equalsIgnoreCase("NA") ) {
log.info(stepDetails.get("Field Name")+" is not applicable for this transaction (as per the testData)");
}
else
{
try
{
input_MandatoryField(stepDetails, testData);
waitFor(stepDetails, testData);
//Find dropdown list
By locator = findByLocator(stepDetails.get("SupportingElement_1_LocatorType"),stepDetails.get("SupportingElement_1_LocatorValue"));
WebElement dd=waitForElementToBeClickable(locator, 50);
List<WebElement> list=dd.findElements(By.tagName("li"));
System.out.println("List size:"+list.size());
for(WebElement temp:list)
{
new WebDriverWait(driver, 20).ignoring(StaleElementReferenceException.class).until(new Predicate<WebDriver>()
{
@Override
public boolean apply(@Nullable WebDriver driver)
{
By locator = findByLocator(stepDetails.get("SupportingElement_1_LocatorType"),stepDetails.get("SupportingElement_1_LocatorValue"));
waitForElementToBeClickable(locator, 60);
return true;
}
});
String str=temp.getText();
System.out.println("list options:"+str);
if(str.contains(value))
{
temp.click();
break;
}
}
}
catch (Exception e) {
e.printStackTrace();
String message = "The specified data in "+ stepDetails.get("Field Name")+ " is not found OR "+ stepDetails.get("Field Name")+ " is not loaded completely after sufficient wait time. Please refer "+ testData.get("TestCaseName")+ ".jpg for more details";
log.info(message);
log.info(e.getMessage());
DriverScript.bResult = "fail";
DriverScript.eMessage = message;
}
}
}
public void input_and_select_MandatoryField( final HashMap<String,String> stepDetails, Map<String,String> testData) throws MyException,Exception
{
String value=testData.get(stepDetails.get("Field Name"));
try
{
input_MandatoryField(stepDetails, testData);
waitFor(stepDetails, testData);
//Find dropdown list
By locator = findByLocator(stepDetails.get("SupportingElement_1_LocatorType"),stepDetails.get("SupportingElement_1_LocatorValue"));
WebElement dd=waitForElementToBeClickable(locator, 50);
List<WebElement> list=dd.findElements(By.tagName("li"));
for(WebElement temp:list)
{
String str=temp.getText();
if(str.equalsIgnoreCase(value))
{
temp.click();
break;
}
}
}
catch (Exception e) {
e.printStackTrace();
String message = "The specified data in "+ stepDetails.get("Field Name")+ " is not found OR "+ stepDetails.get("Field Name")+ " is not loaded completely after sufficient wait time. Please refer "+ testData.get("TestCaseName")+ ".jpg for more details";
log.info(message);
log.info(e.getMessage());
DriverScript.bResult = "fail";
DriverScript.eMessage = message;
}
}
public void verifyElementIsDisplayed(HashMap<String,String> stepDetails, Map<String,String> testData)
{
try {
By locator = findByLocator(stepDetails.get("Locator Type"),stepDetails.get("Locator Value"));
Boolean status=waitForElementToBeClickable(locator,100).isDisplayed();
if(status){
log.info(stepDetails.get("Field Name")+"is displayed");
}
else{
String message = "The specified data in "+ stepDetails.get("Field Name")+ " is not displayed after sufficient wait time. Please refer "+ testData.get("TestCaseName")+ ".jpg for more details";
log.info(message);
DriverScript.bResult = "fail";
DriverScript.eMessage = message;
}
}
catch (Exception e) {
e.printStackTrace();
String message = "The specified data in "+ stepDetails.get("Field Name")+ " is not found OR "+ stepDetails.get("Field Name")+ " is not loaded completely after sufficient wait time. Please refer "+ testData.get("TestCaseName")+ ".jpg for more details";
log.info(message);
log.info(e.getMessage());
DriverScript.bResult = "fail";
DriverScript.eMessage = message;
}
}
public void waitunntillElementIsnotDisplayed(HashMap<String,String> stepDetails, Map<String,String> testData)
{
try {
// Boolean status=true;
Boolean waitFlag=true;
while (waitFlag)
{
//wait for
try
{
By locator1 = findByLocator(stepDetails.get("Locator Type"),stepDetails.get("Locator Value"));
WebDriverWait wait = new WebDriverWait(driver,5);
WebElement element=null;
element=wait.until(ExpectedConditions.elementToBeClickable(locator1));
waitFlag=element.isDisplayed();
System.out.println("element found");
//status=waitForElementToBeClickable(locator,10).isDisplayed();
}
catch (Exception e)
{
e.printStackTrace();
waitFlag=false;
String message=""+stepDetails.get("Field Name")+" is not enabled. Continue execution";
log.info(message);
break;
}
System.out.println("Wait for false condition");
waitFor(stepDetails, testData);
}
}
catch (Exception e)
{
e.printStackTrace();
String message = "The specified data in "+ stepDetails.get("Field Name")+ " is not found OR "+ stepDetails.get("Field Name")+ " is not loaded completely after sufficient wait time. Please refer "+ testData.get("TestCaseName")+ ".jpg for more details";
log.info(message);
log.info(e.getMessage());
DriverScript.bResult = "fail";
DriverScript.eMessage = message;
}
}
public void verifyElementIsnotDisplayed(HashMap<String,String> stepDetails, Map<String,String> testData)
{
try {
By locator = findByLocator(stepDetails.get("SupportingElement_1_LocatorType"),stepDetails.get("SupportingElement_1_LocatorValue"));
Boolean status=true;
String waitFlag="False";
while (waitFlag.equalsIgnoreCase("False"))
{
//wait for
try
{
WebDriverWait wait = new WebDriverWait(driver,10);
WebElement element=null;
element=wait.until(ExpectedConditions.elementToBeClickable(locator));
status=element.isDisplayed();
System.out.println("element found");
//status=waitForElementToBeClickable(locator,10).isDisplayed();
}
catch (Exception e)
{
e.printStackTrace();
status=true;
System.out.println("element is not displayed");
System.out.println("status :"+status);
waitFlag="True";
By locator1 = findByLocator(stepDetails.get("Locator Type"),stepDetails.get("Locator Value"));
waitForElementToBeClickable(locator1,30).click();
String message=""+stepDetails.get("Field Name")+" is not enabled. Continue execution";
log.info(message);
break;
}
System.out.println("status"+status);
System.out.println("Wait for false condition");
waitFor(stepDetails, testData);
}
}
catch (Exception e)
{
e.printStackTrace();
String message = "The specified data in "+ stepDetails.get("Field Name")+ " is not found OR "+ stepDetails.get("Field Name")+ " is not loaded completely after sufficient wait time. Please refer "+ testData.get("TestCaseName")+ ".jpg for more details";
log.info(message);
log.info(e.getMessage());
DriverScript.bResult = "fail";
DriverScript.eMessage = message;
}
}
public void verifyElementIsEnabled(HashMap<String,String> stepDetails, Map<String,String> testData)
{
try {
By locator = findByLocator(stepDetails.get("Locator Type"),stepDetails.get("Locator Value"));
Boolean status=waitForElementToBeClickable(locator,50).isEnabled();
if(status){
log.info(stepDetails.get("Field Name")+"is displayed");
}
else{
String message = "The specified data in "+ stepDetails.get("Field Name")+ " is not displayed after sufficient wait time. Please refer "+ testData.get("TestCaseName")+ ".jpg for more details";
log.info(message);
DriverScript.bResult = "fail";
DriverScript.eMessage = message;
}
}
catch (Exception e) {
e.printStackTrace();
String message = "The specified data in "+ stepDetails.get("Field Name")+ " is not found OR "+ stepDetails.get("Field Name")+ " is not loaded completely after sufficient wait time. Please refer "+ testData.get("TestCaseName")+ ".jpg for more details";
log.info(message);
log.info(e.getMessage());
DriverScript.bResult = "fail";
DriverScript.eMessage = message;
}
}
public WebElement waitForElementToBeClickable(By locator,int waitTime)
{
WebDriverWait wait = new WebDriverWait(driver,waitTime);
WebElement element=null;
try
{
// elementToBeClickable is used for checking an element is visible and enabled such that you can click it
element=wait.until(ExpectedConditions.elementToBeClickable(locator));
System.out.println("element found");
}
catch (Exception e) {
e.printStackTrace();
String message = "Timeout waiting for the element "+ locator +", after "+waitTime+" seconds.";
log.info(message);
log.info(e.getMessage());
DriverScript.bResult = "fail";
DriverScript.eMessage = message;
}
return element;
}
public WebElement waitForElementToBeClickable1(HashMap<String,String> stepDetails, Map<String,String> testData)
{
int waitTime=Integer.parseInt(stepDetails.get("WaitTime"));
WebDriverWait wait = new WebDriverWait(driver,waitTime);
WebElement element=null;
By locator = null ;
try
{
// elementToBeClickable is used for checking an element is visible and enabled such that you can click it
locator = findByLocator(stepDetails.get("Locator Type"),stepDetails.get("Locator Value"));
element=wait.until(ExpectedConditions.elementToBeClickable(locator));
System.out.println("element found");
}
catch (Exception e) {
e.printStackTrace();
String message = "Timeout waiting for the element "+ locator +", after "+waitTime+" seconds.";
log.info(message);
log.info(e.getMessage());
DriverScript.bResult = "fail";
DriverScript.eMessage = message;
}
return element;
}
public boolean waitForTextToBeAsExpected(HashMap<String,String> stepDetails, Map<String,String> testData)
{
WebDriverWait wait = new WebDriverWait(driver,Integer.parseInt(stepDetails.get("WaitTime")));
Boolean status=false;
try
{
String expectedValue=stepDetails.get("ExpectedValue");
By locator = findByLocator(stepDetails.get("Locator Type"),stepDetails.get("Locator Value"));
/* String actualValue=waitForElementToBeClickable(locator,Integer.parseInt(stepDetails.get("WaitTime"))).getText();
System.out.println("actualValue: "+ actualValue+" Expected value: "+expectedValue);
if(actualValue.equalsIgnoreCase(expectedValue)){
System.out.println("As expected");
}*/
wait.until(ExpectedConditions.textToBe(locator,expectedValue));
}
catch (Exception e) {
e.printStackTrace();
String message = "The specified data in "+ stepDetails.get("Field Name")+ " is not found OR "+ stepDetails.get("Field Name")+ " is not loaded completely after sufficient wait time. Please refer "+ testData.get("TestCaseName")+ ".jpg for more details";
log.info(message);
log.info(e.getMessage());
DriverScript.bResult = "fail";
DriverScript.eMessage = message;
}
return status;
}
public void waitForElementToBePresent(HashMap<String,String> stepDetails, Map<String,String> testData)
{
WebDriverWait wait = new WebDriverWait(driver,Integer.parseInt(stepDetails.get("WaitTime")));
try
{
By locator = findByLocator(stepDetails.get("Locator Type"),stepDetails.get("Locator Value"));
wait.until(ExpectedConditions.presenceOfElementLocated(locator));
}
catch (Exception e) {
e.printStackTrace();
String message = "The specified data in "+ stepDetails.get("Field Name")+ " is not found OR "+ stepDetails.get("Field Name")+ " is not loaded completely after sufficient wait time. Please refer "+ testData.get("TestCaseName")+ ".jpg for more details";
log.info(message);
log.info(e.getMessage());
DriverScript.bResult = "fail";
DriverScript.eMessage = message;
}
}
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team