Friday, 10 April 2020

MyCuteBaby Contest - Automatic vote by using java selenium

I had joined MyCuteBaby contest for my daughter. It allows multiple vote after every 30 min. giving vote manually, it is hectic and time consuming process.

Below is the java program which uses selenium library along with chrome driver.


  1.  it open chrome browser
  2.  invoke given contest  url
  3.  click on vote button
  4.  close the opened chrome browser
  5.  This process is repeated after every 31 min.



JAVA PROGRAM:
package seleniun_test;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import java.util.Timer;
import java.util.TimerTask;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class SeleniumTest {
public static final long DELAY = 1860000;
private static final String URL = "http://mycutebaby.in/contest/participant/?n=5e8aa945525c4&utm_source=wsapp_share&utm_campaign=April_2020&utm_medium=shared&utm_term=wsapp_shared_5e8aa945525c4&utm_content=participant";
private static final String FIREFOX_DRIVER = "C:\\Users\\sachin\\Downloads\\geckodriver-v0.26.0-win64\\geckodriver.exe";
private static final String FIREFOX_DRIVER_UNIX = "/usr/bin/geckodriver";
private static final String CHROME_DRIVER_UNIX = "/usr/bin/chromedriver";
private static int count = 0;
// private static Timer timerForMinDispaly = null;

public static void main(String[] args) throws InterruptedException {
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {

@Override
public void run() {
System.out.println(new Date());
try {
runClickJob();
count++;
System.out.println("Count is >>>>>>>>>" + count);
printDateAndTime();
/*
* if(null != timerForMinDispaly ) { timerForMinDispaly.cancel(); } synchronized
* (SeleniumTest.class) { counMins=0; }
*/
// invokeMinDisplay();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}, new Date(), DELAY);

// runClickJob();

}

private static void runClickJob() throws InterruptedException {
// System.setProperty("webdriver.ie.driver",
// "C:\\Users\\sachin\\Downloads\\IEDriverServer_x64_3.4.0\\IEDriverServer.exe");
WebDriver driver = null;
try {
System.setProperty("webdriver.gecko.driver", CHROME_DRIVER_UNIX);

ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("disable-infobars");
chromeOptions.addArguments("start-maximized");

driver = new ChromeDriver(chromeOptions);
driver.manage().deleteAllCookies();
driver.get(URL);
// driver.manage().window().maximize();
// WebElement elementName = driver.findElement(By.className("vote-btn"));
// driver.findElement(By.id("v")).sendKeys("dgfdff");;

WebDriverWait wait1 = new WebDriverWait(driver, 10);
WebElement element1 = wait1.until(ExpectedConditions.elementToBeClickable(By.id("vote_btn")));
/// element1.sendKeys("rtertret");
element1.click();
/*
* //System.out.println(elementName.getText()+"*********"); Thread.sleep(5000);
* elementName.sendKeys("Sachin Rane"); //click elementName.click();
* //driver.findElement(By.id("vote_btn")).click();
*/
Thread.sleep(5000);
//driver.close();

}catch (Exception e) {
System.out.println(e.getMessage());
}finally {
driver.quit();
}
}

private static void printDateAndTime() {
Date today = new Date();

// displaying this date on IST timezone
DateFormat df = new SimpleDateFormat("dd-MM-yy HH:mm:SS z");
df.setTimeZone(TimeZone.getTimeZone("Asia/Kolkata"));
String IST = df.format(today);
System.out.println("Date in Indian Timezone (IST) : " + IST);

}

private static void invokeMinDisplay() {
Timer timerForMinDispaly = new Timer("my_timer");
// System.out.println("Thread.currentThread().getName():"+Thread.currentThread().getName());
timerForMinDispaly.schedule(new TimerTask() {
int counting = 0;

@Override
public void run() {
System.out.println(new Date() + " and minutes elapsed:" + counting);
counting++;
if (counting >= 30) {// for 30 min
// System.out.println("Killling
// Thread.currentThread().getName():"+Thread.currentThread().getName());
Thread.currentThread().stop();
}

}
}, new Date(), 60000);// repeat after every 1 min

}


}

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sachin</groupId>
<artifactId>seleniun_test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
</dependencies>
</project>


Git Repository:

https://github.com/ranesaci/selenium_test



Monday, 26 August 2019

java.security.cert.CertificateException: No subject alternative names present

I was going through 2 way SSL in springboot. I have made all correct configuration service tomcat server and service caller RestTemplate. but I was getting error as "java.security.cert.CertificateException: No subject alternative names present"

After going through solutions, I found, JVM needs this certificate otherwise it gives handshaking error.

Now, how to add this to JVM.

go to jre/lib/security/cacerts file. we need to add our server certificate file to this cacerts file of jvm.

Command to add server cert to cacerts file via command line in windows.

C:\Program Files\Java\jdk1.8.0_191\jre\lib\security>keytool -import -noprompt -trustcacerts -alias <alias_of_ssl_cer_file> -file   <path_of_ssl_cert_file.cer> -keystore <path_of_jdk_cacerts_file>-storepass changeit

Check server cert is installed or not:

C:\Program Files\Java\jdk1.8.0_191\jre\lib\security>keytool -list -keystore cacerts

you can see list of certificates installed:







How to kill already bind port process in windows

When we start our application on already running port, we get port already bind error.

Resolution: for ex. I want to find PID associated with port 8083 and and want to kill process associated with it. go with below steps:


1. go to command line
2. Find process associated with port

C:\Users\sachin.rane>netstat -ano | findstr :8083
  TCP    0.0.0.0:8083           0.0.0.0:0              LISTENING       7576
  TCP    [::]:8083              [::]:0                 LISTENING       7576


3. kill the process

C:\Users\sachin.rane>taskkill /PID 7576 /F
SUCCESS: The process with PID 7576 has been terminated.

Screenshot:




Congratullations!!Its done!!

Monday, 19 August 2019

Install Docker on Windows


Docker in Windows

As we know, Docker is different than hypervisors (Virtual machines) and it uses Linux kernel internally, Docker will need Linux virtual machine on windows, so that it will work on windows as well. Docker provides ‘DockerToolbox’ which provide Virtual box component (by oracle corporation). For windows, Docker use this VM internally to have Linux kernel for its operation.
For Linux, No VM needed as it already having Linux kernel.

Docker toolbox download URL


Once you download, you will see exe file(DockerToolbox.exe) downloaded approx. 211 MB in size.

Installation Screenshots:


Double click on DockerToolbox.exe.





Click on Next button.

Click on Next button.
Check on required checkboxes. Better check all checkboxes.
Click on Install button.

Wait till above installation finished. It will extract and install above checked components.
It may ask to install, ‘Oracle Corporation Universal serial bus’ driver software(It is required for virtual box installation.). Install it.

Click on install button.
Once All things are installed, you will see below window.

Click on finish button. Once finished, you will see 2 shortcuts shown in the file explorer.



Click on ‘Docker Quickstart Terminal’ shortcut Or you can go to it via Windows Start button à Docker Quickstart Terminal.

Windows OS may ask to accept ‘VirtualBox Interface’. Accept it.
Once all installation finished, you will see docker thumbnail on terminal window.

Type ‘docker version’ and you can see all installed docker component versions as shown below:



Congratulations!!! Your Docker setup is successfully done!



Saturday, 24 November 2018

ERROR: Signature extraction failed: Traceback (most recent call last)

I was trying to download youtube playlist in mp3 format. When I tried below command, I was getting "ERROR: Signature extraction failed: Traceback (most recent call last)"

$youtube-dl -cit --extract-audio --audio-format mp3 https://www.youtube.com/playlist?list=PL4uUU2x5ZgR1JOlcY9SZB94MW6fBE8ovU

Solution:

Pulled latest version and it is worked:

sudo wget https://yt-dl.org/latest/youtube-dl -O /usr/local/bin/youtube-dl
sudo chmod a+x /usr/local/bin/youtube-dl
hash -r



Sunday, 10 June 2018

ERROR ReferenceError: is not defined in angular 4

ERROR ReferenceError:  is not defined

Hi, I was adding click event function in angular 4 components html. below is the code for the same.

<span (click)="removeCity(idx)" >remove</span>

and in component ts file, function written as,

 removeCity = function(index) {

        this.cityList.splice(index, 1);

    }

Where cityList is a array of cities defined in ts file.

But, when I was runing the code, I was getting "ERROR ReferenceError:   is not defined in" Then, did followed below steps from terminal to import jquery in app.module.ts

$ npm i jquery --save
$ npm i @types/jquery -D

and imported 'import * as $ from 'jquery';' in app.module.ts

Now, error is vanished.

Saturday, 9 June 2018

Angular4 - node install and upgrade

Angular4 - node install and upgrade

I had installed old version of node js in my laptop ubuntu OS. to start with angular 4 and CLI, we need version more than "node":">= 8.9.0","npm":">= 5.5.1" but my current version is "node":"4.7.2","npm":"3.5.2".

Below are the steps I followed to upgrade and install node with latest version.

First uninstall existing node version.

sachin@sachin-E470:~$ sudo apt-get install --reinstall nodejs-legacy
[sudo] password for sachin:
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 176 not upgraded.
Need to get 30.9 kB of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 http://old-releases.ubuntu.com/ubuntu zesty/universe amd64 nodejs-legacy all 4.7.2~dfsg-1ubuntu3 [30.9 kB]
Fetched 30.9 kB in 20s (1,495 B/s)        
(Reading database ... 275944 files and directories currently installed.)
Preparing to unpack .../nodejs-legacy_4.7.2~dfsg-1ubuntu3_all.deb ...
Unpacking nodejs-legacy (4.7.2~dfsg-1ubuntu3) over (4.7.2~dfsg-1ubuntu3) ...
Setting up nodejs-legacy (4.7.2~dfsg-1ubuntu3) ...
Processing triggers for man-db (2.7.6.1-2) ...
sachin@sachin-E470:~$ sudo n rm 4.7.2
sachin@sachin-E470:~$ sudo npm uninstall -g n
removed 1 package in 0.053s

Install Latest Version:


sachin@sachin-E470:~$ sudo npm cache clean -f
npm WARN using --force I sure hope you know what you are doing.
sachin@sachin-E470:~$ sudo npm install -g n
/usr/local/bin/n -> /usr/local/lib/node_modules/n/bin/n
/usr/local/lib
`-- n@2.1.11

sachin@sachin-E470:~$ sudo n stable

    install : node-v10.4.0
      mkdir : /usr/local/n/versions/node/10.4.0
      fetch : https://nodejs.org/dist/v10.4.0/node-v10.4.0-linux-x64.tar.gz
######################################################################## 100.0%
  installed : v10.4.0


Now, we can check the node version installed as shown below:

sachin@sachin-E470:~$ node -v
v10.4.0


Check node and npm versions:

sachin@sachin-E470:~$ node -v
v10.4.0
sachin@sachin-E470:~$ npm -v
6.1.0

To install CLI:

sachin@sachin-E470:~$ npm install -g @angular/cli

Here -g means it is installed globally and not for specific project.

To check angular CLI installed or not:

sachin@sachin-E470:~$ ng -v

    _                  _ ____ _     ___
   / \  _ __ __ _ _   _| | __ _ _ __   / ___| | |_ _|
  / △ \ | '_ \ / _` | | | | |/ _` | '__|   | | | | | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
               |___/
   

Angular CLI: 6.0.8
Node: 10.4.0
OS: linux x64
Angular:
...

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.6.8
@angular-devkit/core         0.6.8
@angular-devkit/schematics   0.6.8
@schematics/angular          0.6.8
@schematics/update           0.6.8
rxjs                         6.2.0
typescript                   2.7.2


Next - We will see demo for sample project in angular.

Its done!!!!



Wednesday, 21 March 2018

Install Oracle Weblogic Server 12c in Ubuntu/Unix

Install Oracle Weblogic Server 12c in Ubuntu/Unix


  1. Install JDK 1.8 (we will need Oracle JDK. OpenJDK will not be supported.)
  2. Downlolad weblogic from below URL:



3. Keep this  fmw_12.2.1.3.0_wls_Disk1_1of1.zip downloaded file under ‘/home/sachin/weblogic’ folder and extract it.


$cd /home/sachin/weblogic


$unzip  fmw_12.2.1.3.0_wls_Disk1_1of1.zip (To extract zip file)
4. Run this extracted jar from zip file file

5. Click on next button, you will see below screen.


6. We can update the weblogic while installing. As of now, we will skip updates and click on next button.



7. Set ORACLE_HOME and click on next button.




8. Select installation type as ‘Weblogic Server’ and click on next button.




9. Click on next button


10. We will see installation summary as shown below . Then click on Install button.



11. Setup will show progress


12. Once setup finishes all steps, click on next button. We will see Installation complete wizard. Click on Finish button.




13. It will ask create new domain or use existing domain. Here we will create new domain and click on next button.




14. Select Product templates and click on next button.




15. Set username(weblogic) and password(weblogic@1) for weblogic server


16. Set development mode and click on nect button

17. If needed, do some Advanced configuration (Here we are not doing  any)and click on next button.


18. Check configuration summary and click on Create  button.




19. We will see progress of all the steps and then click on Next button


20. We will see domain location and Admin Server url. This is end of installation of weblogic server.




21. Start weblogic server
Go to domain location: /home/sachin/Oracle/Middleware/Oracle_Home/user_projects/domains/base_domain
And run $ sh startWebLogic.sh




22. We will see weblogic start up as shown below:




Enter username and password and click on Login button.




24. Congratullation!!!, you are able to access WebLogic ServerAdministration Console 12c

Happy Learning!!!

Extract error records while inserting into db table using JDBCIO apache beam in java

 I was inserting data into postgres db using apache beam pipeline. it works perfectly with JdbcIO write of apache beam library. But, now, i ...