3/16/19

Selenium with Python | Oracle Database Connectivity using cx_Oracle | Data Driven Testing

About cx_Oracle

cx_Oracle is a Python extension module that enables access to Oracle Database. It conforms to the Python database API 2.0 specification with a considerable number of additions and a couple of exclusions.


Overview

To use cx_Oracle 7 with Python and Oracle Database you need:

Python 2.7 or 3.5 and higher. Older versions of cx_Oracle may work with older versions of Python.

Oracle client libraries. These can be from the free Oracle Instant Client, or those included in Oracle Database if Python is on the same machine as the database. Oracle client libraries versions 18, 12, and 11.2 are supported on Linux, Windows and macOS. Users have also reported success with other platforms.

An Oracle Database. Oracle’s standard client-server version interoperability allows cx_Oracle to connect to both older and newer databases.

Quick Start cx_Oracle Installation

An installation of Python is needed. Python 2.7 and Python 3.5 and higher are supported by cx_Oracle 7.

Install cx_Oracle from PyPI with:

python -m pip install cx_Oracle --upgrade

Pre-requisites

1) Oracle data base
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/12c/r1/Windows_DB_Install_OBE/Installing_Oracle_Db12c_Windows.html

2) Oracle instant client
https://www.oracle.com/technetwork/topics/winsoft-085727.html

3) cx_Oracle though command prompt
Command should execute in command prompt: pip install cx-Oracle

4) cx_Oracle in Pycharm
Select project-->File-->Settings-->Project interpreter--> Click on + -->cx_Oracle-->select-->install package.


Database operations using Pyhton(cx_Oracle Module)

1) Connect to database
2) How to execute queries(insert, update, delete)
3) How to select data from database
4) Data driven testing

Connect to database

import cx_Oracle
import os
os.environ['PATH']='E:\\app\\OracleHomeUser1\\instantclient_18_3'

#Establish connection to the database
con=cx_Oracle.connect("hr","hr","localhost/pdborcl")
print("Connected!!!")
con.close()

How to execute queries(insert, update, delete)

import cx_Oracle
import os
os.environ['PATH']='E:\\app\\OracleHomeUser1\\instantclient_18_3'

#Establish connection to the database
con=cx_Oracle.connect("hr","hr","localhost/pdborcl")

cur=con.cursor()

query1="insert into student values(102,'JOHN')"
query2="update student set sname='XYZ' where sid=102"
query3="delete student where sid=102"

cur.execute(query3)

cur.close()
con.commit()
con.close()

print("Completed!!!")


How to select data from database 

import cx_Oracle
import os
os.environ['PATH']='E:\\app\\OracleHomeUser1\\instantclient_18_3'

#Establish connection to the database
con=cx_Oracle.connect("hr","hr","localhost/pdborcl")

cur=con.cursor()

query="select * From employees"

cur.execute(query)

for cols in cur:
    print(cols[0],"     ",cols[1],"     ",cols[2])

cur.close()
con.close()

print("Completed!!!")


Data Driven testing

from selenium import webdriver
import time
import cx_Oracle
import os
os.environ['PATH']='E:\\app\\OracleHomeUser1\\instantclient_18_3'

driver=webdriver.Chrome(executable_path="C:\Drivers\chromedriver_win32\chromedriver.exe")

driver.get("http://newtours.demoaut.com/")
driver.maximize_window()

#Establish connection to the database
con=cx_Oracle.connect("hr","hr","localhost:1521/pdborcl")

cur=con.cursor()
query="select * From users"
cur.execute(query)

for cols in cur:
    driver.find_element_by_name("userName").send_keys(cols[0])
    driver.find_element_by_name("password").send_keys(cols[1])
    driver.find_element_by_name("login").click()
    time.sleep(5)

    # validation started
    if driver.title == "Find a Flight: Mercury Tours:":
        print("Test passed")
    else:
        print("Test failed")
    driver.find_element_by_link_text("Home").click()

cur.close()
con.close()

print("Data Driven test Completed!!!")




3/13/19

Webservices/API Testing FAQ’s Part-3 SoupUI


43.What is SOAPUI & ReadyAPI?
  • SOAPUI is a Webservices/API Testing tool.
  • SOAPUI Pro (Ready API) which is Licensed version of SOAPUI
44. What is WSDL?
  • WSDL stands for Web Service Description Language and is a document written in XML.
  • It uses XML to define the service layer document which consists of origin of the web service, headers, port types, request and response data.
  • This one can provide the information about web methods and web service.
  • It describes:
  • Origin of the web service
  • Header information
  • Port type
  • Input and output messages
45. What is the role of WSDL document in web service testing?
  • Validating web services in only possible with WSDL document because to configure web services in SoapUI, WSDL document is mandatory. If the WSDL document is not valid, SoapUI will throw an exception immediately.
46. What is UDDI?
  • Universal Description, Discovery and Integration- a directory or global repository where all the web services can be found.
  • A new Webservice can also be registered through this.
  • This is also the place where WSDL detailed definitions are found.
47. What is SOAP?
  • Simple Object access protocol that uses XML to interact with web applications.
  • It uses XML based content to communicate between two client machines across any network
48. What would be the message format of SOAP protocol?
  • Generally, all the SOAP-based web services are written by using XML language which uses standard message format that is accepted across the universe. In this format, it is easy to read, identify the errors, avoids interoperability problems etc.
  • Here’s the sample SOAP message format.
49. What are the advantages of SOAP?
  • Since its XML based, it is platform and programming language independent. RPC (Remote procedure calls) are sometimes blocked by firewalls and proxy servers- Soap overcomes that.
50. SoapUI and SoapUI Pro?
  • SoapUI is a web service testing tool and SoapUI Pro is its commercial version.
  • SoapUI can help create functional, security and load testing test suites.
  • SoapUI Pro does all that with advanced drag and drop, Data Driven testing, advanced reporting and coverage analysis.
51.What we can do with the help of SoapUI?
  • SoapUI offers us to perform automation testing which includes functional testing, load testing and Data Driven testing.
  • It also provides in build reporting tool and export test results
  • We assert our services using various types of assertions
52.What hierarchy does SoapUI follow to build a proper testing project?
  • In a SoapUI project, the following order maintained.
  • TestSuite – This is combination of functional tests and logical blocks
  • Testcase – It’s a group that contains several test steps for the specific aspects of the service.
  • Teststep – it contains the set of functional tests
53.What is the basic method to automate web services in SoapUI?
  • Create a project and add the WSDL file
  • Add test suites, Test cases and Test cases- in that order
  • Include custom programming/validation using by adding Groovy steps
  • Call external data sources if using
  • Add assertions if necessary
  • Then RUN.
54. What are SoapUI assertions?
  • Assertions compare the parts/all of the response message to the expected outcome.
55. What are the major types of assertions available in SoapUI?
Assertions are one of the major features in SoapUI.
It offers the following types of assertions.
  • Simple contains
  • Schema compliance
  • Simple not contain
  • Soap Faults
  • Response SLA
  • XPath Match
  • XQuery Match
  • WS security status
  • Script Assertion
  • WS- Addressing Request or Response Assertion
Additionally, Equals assertion is introduced in SoapUI NG Pro version.
56. Explain about XPath Assertion in SoapUI
In SoapUI, XPath assertion is used for asserting the web service response value by specifying the absolute path.
If the absolute path is matched with the response value, then the test case or test suite will be considered as PASS otherwise it will be notified as FAILED.
We can see the results of assertion at bottom of the screen where the Assertion tab will have resultant information.
57. What is Data Driven testing?
Data Driven testing means to store our test data which includes input and expected output in an external data source called Excel / Database / XML file. Later, we need to iterate the data source using respective component.
In SoapUI, Datasource and Datasource Loop test steps are used for performing data driven testing.
58. What are the different types of assertions used in SoapUI?
The following are the different types of assertions:
Contains & Not Contains
XPath match
XQuery match
Schema compliance
Soap Faults
Response SLA
WS security Status
Script Assertion
WS- Addressing Request or Response Assertion
59. What is Groovy script and where can it be used?
Groovy is a scripting language which internally includes all the Java libraries – it helps us to customize and add custom validations to SoapUI tests
60. How to group tests?
The basic Test suite is a way for us to group tests in SoapUI.
When you need a different set of tests, you just have to create a new test suite and create tests as required under it as test cases.
61.How to save the responses received?
The response values can be saved by clicking on the required request and choosing the “Dump file” location in its properties.
62. What are the properties available in SoapUI?
In SoapUI, there are three levels of properties available. They are,
Custom Properties or Project Level Properties:
These properties are added several times based on our needs and they can be utilized at any test suites, test cases or test steps that belong to the current project.
Test Suite Level Properties:
The tester can add his own properties with relevant information under the test suites. These properties are available for the corresponding test suite only.
Test case Level Properties: If the tester needs to store their test data within the test cases they can create their own properties inside the test case. So these properties can be accessed within the respective test cases.
63. What can data sources be used in SoapUI?
Excel Files
CSV Files
ODBC Sources
SQL / ADO Objects

2/21/19

Webservices/API Testing FAQ’s Part-2 Postman

19. What is Postman?
  • Postman is a rest client software that started as an chrome extension but is now available as native application also.
  • Postman is basically used for API testing in which you can test your APIs with different types of request method types like post, put etc and parameters, headers and cookies.
  • Apart from setting the query parameters and checking the response, postman also let us see different response stats like time, status, headers, cookies etc.  
20. In which type of encoding does postman accept authorization credentials? Why?
  • Postman accept authorization in Base64 encoding only.
  • This is provided inbuilt in Postman or else you can also refer third party websites to convert the credentials in base64.
  • We use base64 particularly because it transmits the data into textual form and send it in easier form such as HTML form data.
  • We use Base64  because we can rely on the same 64 characters in any encoding language that we use.
21.What is meant by the term Environment with respect to Postman?

Webservices/API Testing FAQ’s Part 1

1.What is Client and Server?
  • A server is a connection point for several clients, that will handle their requests. A client is software that (usually) connects to the server to perform actions. The client provide a user interface that allows users to carry out actions.
2. What is Presentation, Business & Database Layer
3. What is an API? Can you give some Examples?
  • An API (Application Programming Interface) is a software intermediary that enables two applications to communicate with each other.
  • In other words it’s a set of functions and procedures that allows the creation of applications which access the features or data of an application or operating system
  • API examples:
  • Google Maps API, Amazon Advertising API, Twitter API, YouTube API, etc.

2/19/19

Handling Dialer Using Appium


Dialer
package SystemApps;

import java.net.URL;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidKeyCode;
import io.appium.java_client.remote.MobileCapabilityType;

public class DailANumber {
   

    public static void main(String[] args) throws Exception {
        // TODO Auto-generated method stub

        DesiredCapabilities dc= new DesiredCapabilities();
       
        dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");


Handling Calculator Using Appium

Calculator
package SystemApps;

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;

public class Calculator {

    public static void main(String[] args) throws MalformedURLException, InterruptedException {

        DesiredCapabilities dc = new DesiredCapabilities();

        dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");

How to Perform Swipe Touch Using Appium

Swipe Touch
import java.net.URL;

import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import io.appium.java_client.MobileDriver;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.touch.offset.ElementOption;

public class Example18SwipeTouchAction {

    public static void main(String[] args) throws Exception {
        // TODO Auto-generated method stub

        DesiredCapabilities dc = new DesiredCapabilities();

        dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");

Handling Ratingstar Using Appium

Rating 3 Star
import java.net.URL;
import java.util.List;

import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.MobileBy;
import io.appium.java_client.MobileDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.touch.offset.ElementOption;
import io.appium.java_client.touch.offset.PointOption;

public class Example14Rating3Star {
   
    public static void main(String[] args) throws Exception {
       
        DesiredCapabilities dc= new DesiredCapabilities();
       
        dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
       
        dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");

Handling Seekbar Using Appium


Seekbar
package NativeApps;
import java.net.URL;
import java.util.List;

import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.MobileBy;
import io.appium.java_client.MobileDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.touch.offset.ElementOption;
import io.appium.java_client.touch.offset.PointOption;

public class Example13SeekBar {
  
    public static void main(String[] args) throws Exception {
      
        DesiredCapabilities dc= new DesiredCapabilities();
      
        dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");

2/18/19

Handling Spinner Using Appium

Spinner
import java.net.URL;
import java.util.List;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.MobileBy;
import io.appium.java_client.MobileDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;

public class Example12SpinnerApiDemo {
   
    public static void main(String[] args) throws Exception {
    DesiredCapabilities dc= new DesiredCapabilities();
       
        dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
       
        dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
       
        dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, "5.1");//Version is number here
       
        dc.setCapability(MobileCapabilityType.DEVICE_NAME, "Android");

Handling Date Picker/Time Using Appium

 
Date Picker/Time
import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;

public class Example11DatePicker {

    public static void main(String[] args) throws MalformedURLException, InterruptedException {
       
        DesiredCapabilities dc= new DesiredCapabilities();
       
        dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
       
        dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
       
        dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, "5.1");//Version is number here
       
        dc.setCapability(MobileCapabilityType.DEVICE_NAME, "Android");
       
        dc.setCapability(MobileCapabilityType.APP, "C:\\apkfiles\\ApiDemos.apk");
       
        URL url =new URL("http://127.0.0.1:4723/wd/hub");

        AndroidDriver driver= new AndroidDriver(url,dc);
       
       
        driver.findElementsById("android:id/text1").get(10).click(); //Views

Handling Expandable List Using Appium

Expandable List
import java.net.URL;
import java.util.List;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;

public class Example10ExpandableList {

        public static void main(String[] args) throws Exception {
        // TODO Auto-generated method stub

        DesiredCapabilities dc= new DesiredCapabilities();
       
        dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
       
        dc.setCapability(MobileCapabilityType.DEVICE_NAME, "Android"); //Android Emulator
       
        dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");

        dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, "5.1");

        //when we ara working on multiple apps we can just copy these lines of command only thing we need to change is apk file location thats it
        dc.setCapability(MobileCapabilityType.APP, "C:\\apkfiles\\ApiDemos.apk");
       
        URL url =new URL("http://127.0.0.1:4723/wd/hub");

Handling Text Box, Check Boxes & Radio Buttons Using Appium

Text Box, Check Boxes & Radio Buttons
import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;

public class Example9CheckboxRadioButtonTextField {

    public static void main(String[] args) throws MalformedURLException {
       
        DesiredCapabilities dc= new DesiredCapabilities();
       
        dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
       
        dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
       
        dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, "5.1");//Version is number here
       
        dc.setCapability(MobileCapabilityType.DEVICE_NAME, "Android");

Handling Horizontal & Vertical Scrolling in Appium

Horizontal Scrolling
import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.MobileDriver;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.touch.offset.ElementOption;

public class Example6HorizontalScrolling {

    public static void main(String[] args) throws MalformedURLException {
   
        DesiredCapabilities dc= new DesiredCapabilities();
       
        dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
       
        dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
       
        dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, "5.1");//Version is number here
       
        dc.setCapability(MobileCapabilityType.DEVICE_NAME, "Android");

2/16/19

Handling Drag & Drop Using Appium

Drag And Drop Action
import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.MobileDriver;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.touch.offset.ElementOption;

public class Example6DragAndDropAction {

    public static void main(String[] args) throws MalformedURLException {
        DesiredCapabilities dc= new DesiredCapabilities();
       
        dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
       
        dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
       
        dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, "5.1");//Version is number here
       
        dc.setCapability(MobileCapabilityType.DEVICE_NAME, "Android");
       
        dc.setCapability(MobileCapabilityType.APP, "C:\\apkfiles\\more\\com.mobeta.android.demodslv-0.5.0-3_APKdot.com.apk");
       
        URL url =new URL("http://127.0.0.1:4723/wd/hub");

        AndroidDriver driver= new AndroidDriver(url,dc);

        //Navigation