Monday, 24 January 2022

Automation using Selenium


<dependencies>
        <!--  https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java  -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.1.0</version>
        </dependency>
        <!--  https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager  -->
        <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>5.0.3</version>
        </dependency>
    </dependencies>
System.setProperty("webdriver.chrome.driver", "drivers/chromedriver");//https://chromedriver.chromium.org/downloads
        or
WebDriverManager.chromedriver().driverVersion("97.0.4692.71").setup();//https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager
        

        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);
       WebDriver driver = new ChromeDriver(chromeOptions);
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
        driver.manage().timeouts().scriptTimeout(Duration.ofMinutes(2));
        driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(100));


        driver.get(BASE_URL);
        driver.manage().window().maximize();
        driver.findElement(By.name("keyword")).sendKeys(PRODUCT_NAME, Keys.ENTER);
        driver.findElement(By.xpath("//input[@placeholder='Enter your pincode']")).sendKeys(pincode);
        driver.findElement(By.xpath("//button[@class='pincode-check']")).click();
        for (int i = 0; i < 10; i++) {
            driver.findElement(By.xpath("//body")).sendKeys(Keys.ARROW_DOWN); //mandatory scroll to find element
        }
        WebElement productAnchorTag = driver.findElement(By.partialLinkText(PRODUCT_NAME));
        String productLink = productAnchorTag.getAttribute("href");
        driver.get(productLink);
        driver.findElement(By.id("add-cart-button-id")).click();
        WebElement proceedToCheckout = driver.findElement(By.cssSelector("a[class='btn marR5']"));
        proceedToCheckout.click();
        String snapdealWindow = driver.getWindowHandle();
        WebDriverWait webDriverWait = new WebDriverWait(driver, 30);
        WebElement loginFB = driver.findElement(By.id("fblogin"));
        loginFB.click();
        Set<String> driverWindowHandles = driver.getWindowHandles();
        for (String windowHandle : driverWindowHandles) {
            if(!driver.getWindowHandle().equals(windowHandle)){
                driver.switchTo().window(windowHandle);
                driver.findElement(By.id("email")).sendKeys(FB_USER_NAME);
                driver.findElement(By.id("pass")).sendKeys(FB_PASSWORD, Keys.ENTER);
                break;
            }
        }
        driver.switchTo().window(snapdealWindow);
        WebElement makePayment = webDriverWait.until(
                ExpectedConditions.visibilityOfElementLocated(By.id("make-payment"))
        );
        if(makePayment.isDisplayed()) {
            driver.findElement(By.id("make-payment")).click();
        }
        driver.close();
        driver.quit();


Appium

Monday, 30 March 2020

Applet

Program to Draw Doraemon:).
import java.awt.*;
import java.applet.*;

public class dora extends Applet{
public void paint(Graphics g){
setBackground(Color.black);

g.setColor(Color.cyan);
g.fillOval(20,20,160,160);//face1

g.setColor(Color.white);
g.drawString("Doraemon",70,200);
g.fillOval(30,40,140,140);//face2
g.fillOval(80,30,20,30);//leftEye
g.fillOval(100,30,20,30);//rightEye

g.setColor(Color.red);
g.fillOval(95,55,10,10);//nose
g.fillArc(50,55,100,100,0,-180);//smile
g.fillRect(62,170,76,10);//belt

g.setColor(Color.yellow);
g.fillOval(93,173,14,14);//bell

g.setColor(Color.black);
g.drawArc(65,120,70,70,22,138);//smileHole
g.fillOval(99,181,2,2);//bell1
g.drawLine(100,183,100,187);//bell2
g.drawArc(90,160,20,20,-45,-90);//bell3
g.drawOval(80,30,20,30);//leftEyeLiner
g.drawOval(100,30,20,30);//rightEyeLiner
g.fillOval(88,42,4,6);//leftEyeBall
g.fillOval(108,42,4,6);//rightEyeBall
//beard
g.drawLine(100,65,100,105);
g.drawLine(50,70,80,80);
g.drawLine(50,85,80,85);
g.drawLine(50,100,80,90);
g.drawLine(120,80,150,70);
g.drawLine(120,85,150,85);
g.drawLine(120,90,150,100);
}
}
/*
<applet code="dora.class" width="200" height="205"></applet>
*/


Output:




Program to Draw Shinchan:/
import java.awt.*;
import java.applet.*;
public class sc2 extends Applet{
public void paint(Graphics g){
g.setColor(Color.pink);
for(int i=0;i<40;i++)
g.drawLine(54,95-i,138,80-i);//cheek to ear
g.setColor(Color.black);
g.fillArc(46,8,94,62,0,180);//up head
for(int i=0;i<7;i++)
g.drawLine(132+i,60,132+i,39);//ear to downHead
g.setColor(Color.pink);
g.fillOval(20,40,60,54);//cheek
g.fillOval(130,60,20,20);//ear
g.fillOval(46,14,86,52);//down head
g.setColor(Color.black);
//EyeBrow
for(int i=0;i<10;i++){
g.drawArc(53,10+i,30,24,0,180);
g.drawArc(90,10+i,30,24,0,180);
}
g.drawArc(53,25,30,24,0,180);
g.drawArc(90,25,30,24,0,180);
//Eye
g.fillOval(53,30,30,24);
g.fillOval(90,30,30,24);
g.setColor(Color.white);
g.fillOval(53+10,30+8,10,10);
g.fillOval(90+10,30+8,10,10);
//mouth
g.setColor(Color.red);
g.fillOval(40,80,22,16);
}
}/*<applet code="sc2" width="170" height="120"></applet>*/

Output:



Sunday, 1 September 2019

C Programming / C++ Programming

//Fibonacci Series using Dynamic Programming and recursion call

//@author : Swarnava Chakraborty
#include<stdio.h>
int arr[20];
int f(int n)
{
if (n==0)
return arr[0];
else if (n==1)
return arr[1];
else{
arr[n]=f(n-1)+f(n-2);
return arr[n];
}
}
int main ()
{
int i, n;
arr[0]=0, arr[1]=1;
printf("Enter the value of n [f(n)] : ");
scanf("%d",&n);
f(n);
for(i=0;i<=n;i++)
printf("%d\t",arr[i]);
        return 0;
}

Output:


//Coin Changes Problem using BackTracking (&Greedy)

//@author : Swarnava Chakraborty
#include<stdio.h>
#include<stdlib.h>
void coin_changes(int coin_value[],int n,int amount){
int i,j=0,sol[n],sol_index[n],amount2=amount,ci=0;
again:
for(i=ci;i<n;i++)
if(amount2>=coin_value[i]){
amount2=amount2-coin_value[i];
sol[j]=coin_value[i];
sol_index[j++]=i;
}
if(amount2!=0){
amount2=amount2+sol[--j];
ci=sol_index[j]+1;
if (ci==sol_index[0]+1)
printf("\nnot possible\n");
else
goto again;
}
for(i=0;i<j;i++)
printf("\n%d",sol[i]);
}
int desc(const void *a,const void *b){
return (*(int *)b - *(int *)a);
}
int main(){
int n, amount=106, coin_value[]={100,3,3,50,5};
n = sizeof(coin_value) / sizeof(coin_value[0]);
qsort(coin_value,n,sizeof(int),desc);
coin_changes(coin_value, n, amount);
return 0;
}

Output:

Time Complexity of coin_changes() :
Worst Case:  [if it apply backtracking method]
= O(n) * O(n-1)
= O(n) * O(n)
= O(n^2)
Best Case: 
= O(1)
Average Case:
= O(n)
Worst Case:  [if it apply greedy]
= O(mn)

Disclaimer :
 If any problem not solve by greedy approach then it apply backtracking method.

//Binary Search using Divide & Conquer Algorithm

#include<stdio.h>
int e;
int bin( int a[],int low, int high) {
    if (low < high) {
        int mid=(low+(high-1))/2;
        if (a[mid]==e)
        printf("elements found in position : %d\n",mid);
        else if(a[mid]>e)
        bin( a, low, mid-1);
        else if(a[mid]<e)
        bin( a, mid+1, high);
    }
}
int main() {
    int n=7, a[20]={1,5,6,8,9,20,25};
    e = 6;//element
    bin( a, 0, n-1 );
}
Output:

Time Complexity of bin() is :
Best Case = O(1)
Worst Case = O(log n)



C++ program to convert  mixed fraction to improper fraction


Input: 5 3/4
Output: 23/4

Program : 
#include <bits/stdc++.h>
using namespace std;

int main(){
    int i1, i2, i3, o1;
   
    cin >>i1 >>i2 >>i3;
    o1 = (i3*i1)+i2;

    if(i3==0 || o1==0 || o1<i3) 
    cout<<"Invalid input";
    else
    cout<<o1<<"\n"<<i3;
   
    return 0;
}





Wednesday, 25 July 2018

Make Animation

Using Pivot Animator






Using Adobe Flash CS6 (Fl)






Using Plotagon

Click on the right side video to view