1| Handling Exception | Assertion
Multiple Catch Blocks
Multiple catch avoid quit tests from various Exception
try
{
assertEquals(actual, expected);
}catch(Exception e)
{
System.out.println("...");
}catch(NullPointerException e)
{
System.out.println("...");
}catch(IOException e)
{
System.out.println("...");
}catch(ComparisonFailure e)
{
System.out.println("...");
}
Multiple Catch Blocks
Multiple catch avoid quit tests from various Exception
try
{
assertEquals(actual, expected);
}catch(Exception e)
{
System.out.println("...");
}catch(NullPointerException e)
{
System.out.println("...");
}catch(IOException e)
{
System.out.println("...");
}catch(ComparisonFailure e)
{
System.out.println("...");
}
Finally Keyword
The finally keyword always executes
try
{
assertEquals(actual, expected);
}catch(Exception e)
{
System.out.println("...");
}finally
{
System.out.println("...");
}
2| Java Arrays
Store values as a list of arrays for assertion.
#1
List<WebElement> savedItem = driver.findElement(By.id(Value)).findElements(By.tagName("li"));
ArrayList<String> storelist = new ArrayList<String>();
for(int i=0; i<savedItem.size(); i++)
{
String d = savedItem.get(i).findElement(By.id(Value)).getText();
storelist.add(d);
System.out.println(storelist.get(i));
}
#2
String content[]={"string1","string2","string3","string4","string5"};
for(int i=0; i<content.length; i++){
if(isElementPresent(By.cssSelector("ul#"+content[i]+" > li")))
{
// Perform your code
}
3| Date Format
Date Format can be asserted using Java DateFormat.
String element = driver.findElement(By.xpath(Value)).getText();
String Result = element.substring(6);
System.out.println(Result);
DateFormat format = new SimpleDateFormat("MMM dd, yyyy"); // Date Format can be modified link
Date dif = format.parse(Result);
System.out.println(dif);
_
Sep 4, 2013
Wed Sep 04 00:00:00 IST 2013
4| Random Select
Elements can be selected randomly using Random().
List<WebElement> element = driver.findElement(By.id(Value)).findElements(By.tagName("li"));
Random r=new Random();
int index = r.nextInt((element.size()-1)-0+1)+0; // int index = r.nextInt(max - min + 1) + min;
String id = element.get(index).getAttribute(Value);
System.out.println(id);
5| Sort Arraylist
Elements can be sorted either in ascending order or descending order.
List<WebElement> savedItem = driver.findElement(By.id(Value)).findElements(By.tagName("li"));
ArrayList<String> storelist = new ArrayList<String>();
for(int i=0; i<savedItem.size(); i++)
{
String d = savedItem.get(i).findElement(By.tagName("a")).getText();
storelist.add(d);
System.out.println(storelist.get(i));
}
Collections.sort(storelist); // Ascending order
System.out.println(storelist);
Collections.reverse(storelist); // Descending order
The finally keyword always executes
try
{
assertEquals(actual, expected);
}catch(Exception e)
{
System.out.println("...");
}finally
{
System.out.println("...");
}
2| Java Arrays
Store values as a list of arrays for assertion.
#1
List<WebElement> savedItem = driver.findElement(By.id(Value)).findElements(By.tagName("li"));
ArrayList<String> storelist = new ArrayList<String>();
for(int i=0; i<savedItem.size(); i++)
{
String d = savedItem.get(i).findElement(By.id(Value)).getText();
storelist.add(d);
System.out.println(storelist.get(i));
}
#2
String content[]={"string1","string2","string3","string4","string5"};
for(int i=0; i<content.length; i++){
if(isElementPresent(By.cssSelector("ul#"+content[i]+" > li")))
{
// Perform your code
}
3| Date Format
Date Format can be asserted using Java DateFormat.
String element = driver.findElement(By.xpath(Value)).getText();
String Result = element.substring(6);
System.out.println(Result);
DateFormat format = new SimpleDateFormat("MMM dd, yyyy"); // Date Format can be modified link
Date dif = format.parse(Result);
System.out.println(dif);
_
Sep 4, 2013
Wed Sep 04 00:00:00 IST 2013
4| Random Select
Elements can be selected randomly using Random().
List<WebElement> element = driver.findElement(By.id(Value)).findElements(By.tagName("li"));
Random r=new Random();
int index = r.nextInt((element.size()-1)-0+1)+0; // int index = r.nextInt(max - min + 1) + min;
String id = element.get(index).getAttribute(Value);
System.out.println(id);
5| Sort Arraylist
Elements can be sorted either in ascending order or descending order.
List<WebElement> savedItem = driver.findElement(By.id(Value)).findElements(By.tagName("li"));
ArrayList<String> storelist = new ArrayList<String>();
for(int i=0; i<savedItem.size(); i++)
{
String d = savedItem.get(i).findElement(By.tagName("a")).getText();
storelist.add(d);
System.out.println(storelist.get(i));
}
Collections.sort(storelist); // Ascending order
System.out.println(storelist);
Collections.reverse(storelist); // Descending order
Amazing, thanks a lot my friend, I was also siting like a your banner image when I was thrown into Selenium.
ReplyDeleteWhen I started learning then I understood it has got really cool stuff.
I can vouch webdriver has proved the best feature in Selenium framework.
thanks a lot for taking a time to share a wonderful article.
Best Selenium Training Institute in Chennai
Selenium Training in Velachery
Automation testing mainly focus on Java training in chennai and needs java knowledge.So we need to get Java training in chennai to be expert in selenium. All the training were listed in software testing training in chennai
ReplyDeleteThis is really very nice and informative article Thanks for sharing this type of article & keep posting amazing article. keep it up.
ReplyDeletetechnical updates
Latest updates
kyrie 7
ReplyDeletesupreme clothing
jordan shoes
bape
kyrie 7 shoes
kobe shoes
jordan 6
russell westbrook shoes
yeezy boost 350
bape