Monday, August 24, 2020

selenium webdriver tutorials

  

First Selenium Program

 

1.eclipse download

 

2.File->New ->Java Project àProjectname àFinish

3.selenium software download for java

https://www.selenium.dev/downloads/

 


 

 4.go to eclipse project right click the library folder

 


 

5.build path-àconfig build path


6.Add external jars (selenium library files add)


 

7.Apply and close

8.coding type

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

public class s {

 

       public static void main(String[] args) {

              // TODO Auto-generated method stub

 

              System.setProperty("webdriver.chrome.driver","D:\\chromedriver.exe");

              WebDriver driver = new ChromeDriver();

        driver.get("https://www.google.com");

       }

 

}

  

2.Locators Check

 

Name  Locator

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

public class s {

 

       public static void main(String[] args) {

              // TODO Auto-generated method stub

 

              System.setProperty("webdriver.chrome.driver","D:\\chromedriver.exe");

              WebDriver driver = new ChromeDriver();

        driver.get("https://www.google.com");

        driver.findElement(By.name("q")).sendKeys("tech");

        driver.findElement(By.name("btnK")).submit();

       }

 

}

 

 

Id Locator

 

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

public class s {

 

       public static void main(String[] args) {

              // TODO Auto-generated method stub

 

              System.setProperty("webdriver.chrome.driver","D:\\chromedriver.exe");

              WebDriver driver = new ChromeDriver();

        driver.get("https://www.facebook.com");

        driver.findElement(By.id("email")).sendKeys("tech");

       }

 

}

 

Xpath Locator

 

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

public class s {

 

       public static void main(String[] args) {

              // TODO Auto-generated method stub

 

              System.setProperty("webdriver.chrome.driver","D:\\chromedriver.exe");

              WebDriver driver = new ChromeDriver();

        driver.get("https://www.facebook.com");

        driver.findElement(By.xpath("//*[@id=’email’]")).sendKeys("tech");

       }

 

}


 

Link Text

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

public class s {

 

       public static void main(String[] args) {

              // TODO Auto-generated method stub

 

              System.setProperty("webdriver.chrome.driver","D:\\chromedriver.exe");

              WebDriver driver = new ChromeDriver();

        driver.get("https://www.facebook.com");

        driver.findElement(By.linkText("Forgotten account?")).click();

      

       }

 

}

 

Partial Link Text

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

public class s {

 

       public static void main(String[] args) {

              // TODO Auto-generated method stub

 

              System.setProperty("webdriver.chrome.driver","D:\\chromedriver.exe");

              WebDriver driver = new ChromeDriver();

        driver.get("https://www.facebook.com");

        driver.findElement(By.partialLinkText("Forgotten")).click();

      

       }

 

}

 

CssSelector

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

public class s {

 

       public static void main(String[] args) {

              // TODO Auto-generated method stub

 

              System.setProperty("webdriver.chrome.driver","D:\\chromedriver.exe");

              WebDriver driver = new ChromeDriver();

        driver.get("https://www.facebook.com");

        driver.findElement(By.cssSelector("#u_0_m")).sendKeys("hai");

      

       }

 

}

 

Check Box and Radio Button

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

public class s {

 

       public static void main(String[] args) {

              // TODO Auto-generated method stub

 

              System.setProperty("webdriver.chrome.driver","D:\\chromedriver.exe");

              WebDriver driver = new ChromeDriver();

        driver.get("http://demo.guru99.com/test/radio.html");

        driver.findElement(By.id("vfb-7-1")).click();

        driver.findElement(By.id("vfb-6-0")).click();

       

      

       }

 

}

 

DropDown

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.support.ui.Select;

 

public class s {

 

       public static void main(String[] args) {

              // TODO Auto-generated method stub

 

              System.setProperty("webdriver.chrome.driver","D:\\chromedriver.exe");

              WebDriver driver = new ChromeDriver();

        driver.get("http://demo.guru99.com/test/newtours/register.php");

        Select s = new Select(driver.findElement(By.name("country")));

        s.selectByVisibleText("INDIA");

      

       }

 

}

 

Webtable

Html file

 

<html>

<body>

<table border=”1”>

<tbody>

<tr>

<td>

First

</td>

<td>

Second

</td>

</tr>

</tbody>

</table>

 


 

Code

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.support.ui.Select;

 

public class s {

 

       public static void main(String[] args) {

              // TODO Auto-generated method stub

 

              System.setProperty("webdriver.chrome.driver","D:\\chromedriver.exe");

              WebDriver driver = new ChromeDriver();

        driver.get("file:///C:/Users/ADMIN/Desktop/webtable.html");

      String adriver.findElement(By.xpath("/html/body/table/tbody/tr/td[2]")).getText();

      System.out.println(a);

       }

 

}

 

 

Installing TestNG in Eclipse

Go to Help Install new Software

 


 

 

Step 2

Paste the link http://dl.bintray.com/testng-team/testng-eclipse-release/


 

Click add button install testing

 

First TestNG project

 

Step 1

File->New ->other->TestNG->TestNG class


 

Click next

 


Create the testing project click finish

Right click the project folderàbuild path-àconfigurebuild path-àadd Library


Add TestNG library

 

 

Program

package p1;

 

import org.testng.annotations.Test;

import org.openqa.selenium.*;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.Assert;

import org.testng.annotations.*;

 

public class testngexample {

  @Test

  public void f() {

         System.setProperty("webdriver.chrome.driver","D:\\chromedriver.exe");

              WebDriver driver = new ChromeDriver();

      driver.get("https://www.google.com");

 

        

  }

}

 

Run


 

Getting html report

 

1.Right click the project folder

2.Click refresh

3.test-output folder(click index.html) get the html report

 

 

Annotation using TestNG

package p1;

 

import org.testng.annotations.Test;

import org.testng.annotations.BeforeTest;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.annotations.AfterTest;

 

public class NewTest {

 

              WebDriver driver ;

 

       @Test

  public void f() {

             

              driver= new ChromeDriver();

                 driver.get("https://www.google.com");

  }

  @BeforeTest

  public void beforeTest() {

         System.setProperty("webdriver.chrome.driver","D:\\chromedriver.exe");

             

  }

 

  @AfterTest

  public void afterTest() {

         driver.close();

  }

 

}

 

TestPrioirty

 

package p1;

 

import org.testng.annotations.Test;

import org.testng.annotations.BeforeTest;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.annotations.AfterTest;

 

public class NewTest {

 

              WebDriver driver ;

 

        @Test(priority = 1)

 

  public void f() {

             

              driver= new ChromeDriver();

                 driver.get("https://www.google.com");

  }

    @Test(priority = 0)

 

  public void beforeTest() {

         System.setProperty("webdriver.chrome.driver","D:\\chromedriver.exe");

             

  }

 

    @Test(priority = 2)

 

  public void afterTest() {

         driver.close();

  }

 

}

 

MultiSessions

 

 

package p1;

 

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.annotations.Test;

 

public class NewTest123 {

      

 

  @Test

  public void f() {

         System.setProperty("webdriver.chrome.driver","D:\\chromedriver.exe");

         WebDriver drivernew ChromeDriver();

                 driver.get("https://www.google.com");

  }

 

  @Test

  public void f1() {

         System.setProperty("webdriver.chrome.driver","D:\\chromedriver.exe");

         WebDriver drivernew ChromeDriver();

                 driver.get("https://www.facebook.com");

  }

 

 

}

Now create TestNG.xml


 

 


 

TestNG.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">

<suite name="Suite">

  <test thread-count="5" name="Test">

    <classes>

      <class name="p1.NewTest123"/>

      <class name="p1.example"/>

    </classes>

  </test> <!-- Test -->

</suite> <!-- Suite -->

 

 

 

Run the program

 

 


 

 

Multiple Test Suites

 

Package 1(package p1)

package p1;

 

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.annotations.Test;

 

public class NewTest123 {

      

 

  @Test

  public void f() {

         System.setProperty("webdriver.chrome.driver","D:\\chromedriver.exe");

         WebDriver drivernew ChromeDriver();

                 driver.get("https://www.google.com");

  }

 

 

 

}

 

 

Package 2(package p1)

package p2;

 

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.annotations.Test;

 

public class NewTest {

  @Test

  public void f() {

         System.setProperty("webdriver.chrome.driver","D:\\chromedriver.exe");

         WebDriver drivernew ChromeDriver();

                 driver.get("https://www.facebook.com");

  }

}

 

TestNG.xml

 

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">

<suite name="Suite">

  <test thread-count="5" name="Test">

    <classes>

      <class name="p1.NewTest123"/>

      <class name="p2.NewTest"/>

    </classes>

  </test> <!-- Test -->

</suite> <!-- Suite -->

 

TestNG Report Generation

 

Emailable-report.html

 


 



 

2.index.html

 


 


 

3.Report Class

 

Example

 

package p2;

 

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.Reporter;

import org.testng.annotations.Test;

 

public class NewTest {

  @Test

  public void f() {

         System.setProperty("webdriver.chrome.driver","D:\\chromedriver.exe");

         Reporter.log("the browser open");

 

         WebDriver drivernew ChromeDriver();

         Reporter.log("the browser type");

                 driver.get("https://www.facebook.com");

  }

}

 

Run the TestNG.xml file and refresh the folder

Open the emailable.html

 


 

Then we get the output

 

Take ScreenShot

Add commons-io-2.7.jar file to build path then

 

program

 

package p2;

 

import java.io.File;

 

import org.openqa.selenium.OutputType;

import org.openqa.selenium.TakesScreenshot;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.Reporter;

import org.testng.annotations.Test;

 

public class NewTest {

  @Test

  public void f() {

         System.setProperty("webdriver.chrome.driver","D:\\chromedriver.exe");

        

 

         WebDriver drivernew ChromeDriver();

      

                 driver.get("https://www.facebook.com");

                

                 TakesScreenshot scrShot =((TakesScreenshot)driver);

           File src=scrShot.getScreenshotAs(OutputType.FILE);

           File DestFile=new File("D://");

           FileUtils.copyFile(srcDestFile);

  }

}

 

 

 

 

 

Python Tutorial

 Professional Program Online Tutorials(PPT)



Python 

Python:
             Python can be used to write simple programs, but it also possesses the full power required to create complex, large-scale enterprise solutions.

 the ways in which Python is used includes:

  • Desktop graphical application development, including games;
  • Mathematical and scientific analysis of data; and
  • Web and internet development.

                                Hello world using python

  print("hai")

  output

        hai

                               Adding two integers in python

a=10

b=20

c=a+b

print(c)

 

output

30

                           Adding two decimal numbers

a=10.10

b=20.2

c=a+b

print(c)

output

30.299999999999997

                               String variable print

 

a="sabari"

print(a)

 

output

sabari

 

 

                    Runtime input (String)

 

a=input()

print(a)

 

output

sabari

sabari

 

                        Runtime input(int)

 

a=int(input())

b=int(input())

c=a+b

print(c)

 

output

23

32

55

                          Runtime decimal numbers(float)

a=float(input())

b=float(input())

c=a+b

print(c)

output

20.1

20.2

40.3


 

                            Conditional Statements

If-else syntax

If(condition check):

    Statement;

else:

   statement;

 

example

a=int(input())

b=int(input())

if(a>b):

    print("a is big")

else:

    print("b is big")

 

output

23

21

a is big

 

if-else if

syntax

if(condition check):

   statement;

elif(condition check):

   statement;

else:

  statement;

 

example

 

a=int(input())

b=int(input())

c=int(input())

 

if(a>b and a>c):

    print("a is big")

elif(b>a and b>c):

    print("b is big")

else:

    print("c is big")

 

output

12

22

33

C is big

Nested if

Syntax

  If(condition check):

      If(condition check):

          Statement

    else:

          statement

  else:

       Statement

Example

a=10

if(a>5):

    if(a<20):

        print("a is between 5 to 20")

    else:

        print("a is above 20")

 

else:

    print("a is less then 5")

output

a is between 5 to 20

                                    LOOPINGS 

for loop

syntax

for variable in range(start,end):

     statement

ex

for i in range(1,10):

     print(i)

output

1

2

3

4

5

6

7

8

9

Example 2

for i in range(10):

     print(i)

output

0

1

2

3

4

5

6

7

8

9

 

Example 3

for i in range(2,20,2):

     print(i)

output

 2

4

6

8

10

12

14

16

18

 

While loop

Syntax

Initialize;

While(condition check):

  Statement

  Inc/dec

 

Example

 

i=0

while(i<5):

    print("hai")

    i=i+1

output

hai

hai

hai

hai

hai


break

 

i=0

while(i<5):

    print("hai")

 

    i=i+1

    if(i==3):

        break

output

hai

hai

hai


continue

 

i=0

while(i<5):

    i=i+1

  

    if(i==3):

        continue

 

    print(i)

   

 output

1

2

4

5

 

                        Strings

 

Example 1

a="sabari"

print(a)

a='sabari'

print(a)

 

output

sabari

sabari

Example 2(index print)

a="hello"

print(a[0])

output

h

Example 3(index particular)

a="hello"

print(a[1:3])

output

el

Example 4(index upto)

a="hello"

print(a[:3])

output

hel

example 5(index with reverse)

a="hello"

print(a[-1])

 

output

o

example 5(delete the string)

a="hello"

del a

                                String methods

1.index

a="hello this is python program"

b=a.index("this")

print(b)

output

6

2.upper

a="hello this is python program"

b=a.upper()

print(b)

output

HELLO THIS IS PYTHON PROGRAM

3.lower

a="HELLO"

b=a.upper()

print(b)

output

hello

4.isdigit()

a="hello"

print(a.isdigit())

output

False

 

5.isdecimal()

a="5"

print(a.isdecimal())

output

True

6. capitalize()

a="hello this is python"

print(a.capitalize())

output

Hello this is python

7.startswith()

a="hello this is python"

print(a.startswith('h'))

output

True

8.endswith()

a="hello this is python"

print(a.endswith('h'))

output

False

 

9.replace()

a="hello this is python"

a=a.replace("hello","welcome")

print(a)

output

welcome this is python

 

Functions example

 

Syntax

def  functionname():#delcare/define

    statement

functionname() #calling

example

#define

def sabari():

    print("hai")

 

#calling

sabari()

output
hai

Function with argument

#define

def sabari(fname):

    print(fname)

 

#calling

sabari("sabari")

output

sabari

 

Lambda expression

Synax

Lambda arguments:Expression


Example 

x=lambda a:a+10

print(x(5))

output

15

 

2 values

x=lambda a,b:a*b

print(x(5,5))

output

25

 

Arrays

 

cars=["bmw","ford","volvo"]

print(cars)

output

["bmw","ford","volvo"]

 

One by one print

cars=["bmw","ford","volvo"]

for i in cars:

    print(i)

output

bmw

ford

Volvo

 

Adding array

cars=["bmw","ford","volvo"]

cars.append("hello")

for i in cars:

    print(i)

output

bmw

ford

Volvo

hello

Remove(pop)

cars=["bmw","ford","volvo"]

cars.pop(1)

for i in cars:

    print(i)

output

bmw

volvo

remove keyword

cars=["bmw","ford","volvo"]

cars.remove("bmw")

for i in cars:

    print(i)

output

ford

Volvo

                                            Python collections

1.List

Ordered and changeable,duplicates

2.Tuple

Order and unchange able,duplicate

3.set

Un order and un index (no duplicates)

4.dictionary

Unordered,changeable and indexed(no duplicates)

 


1.List

Example

a=["apple","banana","cherry"]

print(a)

a[1]="orange"

print(a)

output

['apple', 'banana', 'cherry']

['apple', 'orange', 'cherry']

 

Example(list with index)

a=["apple","banana","cherry"]

print(a[1])

output

banana

 

Example (negative index)

a=["apple","banana","cherry"]

print(a[-1])

output

cherry

 

append

 

a=["apple","banana","cherry"]

a.append("orange")

print(a)

 

ouput

['apple', 'banana', 'cherry', 'orange']

 

Insert

a=["apple","banana","cherry"]

a.append("orange")

a.insert(1,"wel")

print(a)

 

ouput

['apple',’wel’, 'banana', 'cherry', 'orange']

 

Remove

a=["apple","banana","cherry"]

a.remove("apple")

print(a)

output

banana,cherry

 

pop

a=["apple","banana","cherry"]

a.pop()

print(a)

output

['apple', 'banana']

 

                                                       Tuples

Example

a=(101,'sabari',10)

print(a[0])

 

output

101

 

Example 2

a=(101,'sabari',10)

for i in a:

    print(i)

output

101

sabari

10

                                    Set

 

Example

 

days={"sabari","nathan","mca","sabari"}

print(days)

 

output

{'mca', 'sabari', 'nathan'}

 

Add

days={"sabari","nathan","mca","sabari"}

print(days)

days.add("monday")

print(days)

output

{'monday', 'sabari', 'nathan', 'mca'}

 

                                            Dictionary

example

emp={"Name":"sabari","Age":25}

print(emp)

output

{'Name': 'sabari', 'Age': 25}

 

Example

emp={"Name":"sabari","Age":25}

print(emp["Name"])

output

sabari

 

                                                             Class and objects

 

class A:

    x=5

 ob=A()

print(ob.x)

 output

                                           Constructor

class A:

  def __init__(self):

      print("hai")

  

ob=A()

 

output

hai

 

class and objects with functions

class A:

  def get(self,name):

      print("hai ",name)

  

ob=A()

ob.get("sabari")

output

sabari

 

modules

 

sd.py

def sabari():

    print("hai")

 

gg.py

 

import sd

 

sd.sabari()

 

output

hai

 

 

 




Wednesday, June 3, 2020

Jsp tutorial


JSP HELLO WORLD

Eclipse-->new -->Dynamic Web Project
---->webcontent--->jsp file

Program


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<%

out.println("hai");



%>



</body>
</html>

Run Program

right click-->run as--->run server--->apache tomact 7.0




Addition of two numbers using jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<%

int a,b,c;
a=10;
b=20;
c=a+b;
out.println("c is "+c);



%>



</body>
</html>


O/P

c is 30


Run time input

exam.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<form action="exam1.jsp" method="post">

Username <input type="text" name="n1"><br><br>
Password <input type="password" name="n2"><br><br>

<input type="submit">

</form>


</body>
</html>


exam1.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%

String a=request.getParameter("n1");
String b=request.getParameter("n2");

out.println(a);
out.println("<br>");
out.println(b);


%>




</body>
</html>


if-else

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<form action="exam1.jsp" method="post">

a <input type="text" name="n1"><br><br>
b <input type="text" name="n2"><br><br>

<input type="submit">

</form>


</body>
</html>

exam1.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%

int a,b;
a=Integer.parseInt(request.getParameter("n1"));
 b=Integer.parseInt(request.getParameter("n2"));
if(a>b)
{
out.println("a is big");
}

else
{
out.println("b is big");
}

%>




</body>
</html>

username and password checking

exam.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<form action="exam1.jsp" method="post">

username <input type="text" name="n1"><br><br>
password<input type="password" name="n2"><br><br>

<input type="submit">

</form>


</body>
</html>

exam1.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%

String a,b;
a=request.getParameter("n1");
 b=request.getParameter("n2");
if(a.equals("admin") && b.equals("admin"))
{
out.println("correct password");
}

else
{
out.println("wrong password");
}

%>




</body>
</html>

Python Technical Interview Questions

 1)first non repeating character Malayalam y programming p str = "MalayalaM" a = '\0' for c in str:     if str.index(c) ==...