Saturday, September 17, 2016

[SOLUTION] Content Assistant CTRL+Space Not Working in Eclipse

Recently I faced the issue in Eclipse were my CTRL+Space (Content Assistant) was not working. Everytime I press CTRL+Space eclipse shows nothing. Finally I managed to find the solution by changing the Preferences of my Eclipse editor.

Windows > Preferences > Java > Editor > Advanced. Make sure 'Java Proposals' is checked.


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

Wednesday, June 22, 2016

[TIPS] Wait for Page Load in Selenium Webdriver

Selenium WebDriver supports implicit wait (applies on findElement and findElements) and explicit wait (works with some explicit condition specified by automation tester on page element. Check Selenium 2 library for more details).

Using selenium WebDriver with Java script we can wait for Page load condition.

I created below method under my UIAction class which I re-used.
public boolean waitForPageLoad(long seconds) {
try {
new WebDriverWait(driver, seconds).until(new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver wdriver) {
return ((JavascriptExecutor) driver).executeScript("return document.readystate").equals("complete");
}
});
return true;
} catch (Exception e) {
System.out.println("Method waitForPageLoad: Exception " + e.getMessage());
return false;
}
}

Now above code executed JavaScript code "document.readystate" which return following 5 string values:
uninitialized - page loading not yet started
loading - page loding inprogress
loaded - page loaded
interactive - user can intereact with fields
complete - page fully loaded

BitBucket: Facing issue with SSH key for repo

Below is the error message displayed while push in origin master

conq: repository access denied. deployment key is not associated with the reques
ted repository.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

One of the best solution provide here

Tuesday, May 31, 2016

Install Maven on Linux or Unix system by command line

Steps to install Maven on Linux or Unix machine:

1. Open Maven binaries from link
2. Pick the latest one for 
Eg. http://mirror.olnevhost.net/pub/apache/maven/binaries/apache-maven-3.2.2-bin.tar.gz
3. Navigate to /usr/local/maven Type command 
  $ wget http://mirror.olnevhost.net/pub/apache/maven/binaries/apache-maven-3.2.2-bin.tar.gz
4. Type command to extract the tar file. 
   $ tar xvf apache-maven-3.2.2-bin.tar.gz
5. Add environment variable-
   export M2_HOME=/usr/local/maven/apache-maven-3.2.2
$ export M2=$M2_HOME/bin
$ export PATH=$M2:$PATH
6. Check if Maven is install by below command -
$ mvn -version

[EDIT-Install straight forward with single command]
sudo apt install maven


Thursday, March 17, 2016

Demo Practice website for Selenium Automation Testing

Here are some demo sites for learning Selenium Automation Testing using Selenium IDE or Selenium RC (Selenium Remote control) or Selenium Webdriver.

E-commerce website - http://store.demoqa.com/
Basic fields demo portal - http://demoqa.com/
Automation demo web page practice - http://toolsqa.com/automation-practice-form/
Switch window - http://toolsqa.com/automation-practice-switch-windows/
Handling browsers alerts - http://toolsqa.com/handling-alerts-using-selenium-webdriver/
iFrame practice - http://toolsqa.com/iframe-practice-page/

Wednesday, March 2, 2016

Useful Unix or Linux command on single post

Get process id of all the running program on Unix or Linux system.
ps ax | grep java

OUTPUT:
22491 pts/0    S+     0:00 grep --color=auto java
27209 ?        S      0:00 sudo nohup java
27210 ?        Sl     2:58 java

Kill process using process id (PDID) in unix or linux:
sudo kill -9 27210

Below command will fetch count of files in a particular director in Unix or Linux system?


ls -l | grep -v ^l | wc -l

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

Tuesday, January 5, 2016

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