Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Saturday, January 28, 2017

[TIPS] Selenium Implicit Wait - Turn ON and OFF

While automating web application Selenium Webdriver Implicit wait is applied to all findElement and findElements keyword till the element is visible. But in some case we need to check if fields visibility immediately on performing some actions. So why to wait for default implicit wait of 15 or 30 seconds.

Here is the simple tip to override Implicit default wait time by Turning OFF the implicit wait while performing action and validating field visibility. Below Java code snippet will be helpful -

 public void turnOFFImplicitWait(Webdriver driver)  {  
   driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);  
 }  

After verifying the step turn ON default implicit wait as below -
 public void turnONImplicitWait(Webdriver driver)  {  
   driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);  
 }  

Friday, July 8, 2016

[TIPS] Extract digit or non-digit from String using JAVA

Single line command to extract digit from a String
Eg. text = All (68)

text = text.replaceAll("\\D+", "");

Output - text = 68

Now \D represent the digit character i.e. 68
Also \d represent the non-digit character i.e. All ()
+ represent one or more time

Tuesday, January 26, 2016

Find text in table without table iteration

Normally we follow the approach of iterating table, find the required text and perform some operation on same row. This approach is fast for small table but when it comes to very large table iteration will be slow enough.

Instead without iterating the table find the text using xpath and perform operation on same row.

Let take an example:









From above table we want 'Travel' time (column = 7) of particular train from 'Train No' (column=1).

String travelTime = driver.findElement(
By.xpath("//table[@id='trainInfo']/tbody/tr/td[text()='19215']/../td[7]")).getText();

OUTPUT:
Travel time: 15.35

Monday, January 18, 2016

Generate Random Alphanumeric String using Java

Below method will generate random Alphanumeric string of specified length using Java -

public static String randomString(int length) {
String strRandom = RandomStringUtils.randomAlphanumeric(length);
return strRandom;
}


OUTPUT:
pX03qt8

Friday, August 14, 2015

How to display static variable in java debug mode | Eclipse IDE

How to display static variable in java debug mode?
Click on arrow key pointing downward direction > Java > check Show static variable.
Refer below image -

How to displaye static variable in java debug mode?

Read CSV from S3

 import csv def count_records(csv_file):     record_count = 0     first_line = None     last_line = None     # Open the CSV file and read it...