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

Tuesday, January 19, 2016

[ERROR]How to resolve "Multiple annotations found at this line" in pom.xml file?

Today while creating new project I came across below error message in POM.xml file after deleting Junit dependencies and including TestNG dependencies and worried how to solve. Luckily I found solution from my preview project.

Multiple annotations found at this line:
- ArtifactTransferException: Failure to transfer org.apache.httpcomponents:httpclient:jar:
4.5.1 from http://repo.maven.apache.org/maven2 was cached in the local repository, resolution 
will not be reattempted until the update interval of central has elapsed or updates are forced. 
Original error: Could not transfer artifact org.apache.httpcomponents:httpclient:jar:4.5.1 from/to 
central (http://repo.maven.apache.org/maven2): connection timed out to http://
repo.maven.apache.org/maven2/org/apache/httpcomponents/httpclient/4.5.1/httpclient-4.5.1.jar
- ArtifactTransferException: Failure to transfer org.apache.httpcomponents:httpcore:jar:
4.4.3 from http://repo.maven.apache.org/maven2 was cached in the local repository, resolution 
will not be reattempted until the update interval of central has elapsed or updates are forced. 
Original error: Could not transfer artifact org.apache.httpcomponents:httpcore:jar:4.4.3 from/to 
central (http://repo.maven.apache.org/maven2): connection timed out to http://
repo.maven.apache.org/maven2/org/apache/httpcomponents/httpcore/4.4.3/httpcore-4.4.3.jar
- ArtifactTransferException: Failure to transfer commons-logging:commons-logging:jar:1.2 
from http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not 
be reattempted until the update interval of central has elapsed or updates are forced. Original 
error: Could not transfer artifact commons-logging:commons-logging:jar:1.2 from/to central (http://
repo.maven.apache.org/maven2): connection timed out to http://repo.maven.apache.org/
maven2/commons-logging/commons-logging/1.2/commons-logging-1.2.jar

SOLUTION:
Just include below "httpclient" dependencies solved my problem.
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.4</version>
</dependency>

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

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...