вторник, 15 мая 2018 г.

AQA: Java - Простой пример работы с Property файлами в Java

Property файлы присутствуют практически в каждом проекте, и сейчас я вам покажу простой пример их использования, а также расскажу, зачем они и где используются.

Шаг 0. Создание проекта

Начнем с того что создадим простой Maven проект, указав название и имя пакета:

prop_1

Структура, которая получится в конце проекта довольно таки простая.


Как видите у нас только два файла, первый – Main.java, а второй – config.properties.


четверг, 3 мая 2018 г.

AQA: Selenium - WebDriver - Database Testing using Selenium: Step by Step Guide


Selenium Webdriver is limited to Testing your applications using Browser. To use Selenium Webdriver for Database Verification you need to use the JDBC ("Java Database Connectivity").
JDBC (Java Database Connectivity) is a SQL level API that allows you to execute SQL statements. It is responsible for the connectivity between the Java Programming language and a wide range of databases. The JDBC API provides the following classes and interfaces
  • Driver Manager
  • Driver
  • Connection
  • Statement
  • ResultSet
  • SQLException
In order to test your Database using Selenium, you need to observe the following 3 steps
1. Make a connection to the Database
2. Send Queries to the Database
3. Process the results
Database Testing using Selenium: Step by Step Guide

1) Make a connection to the Database

In order to make a connection to the database the syntax is
DriverManager.getConnection(URL, "userid", "password" )
Here,
  • Userid is the username configured in the database
  • Password of the configured user
  • URL is of format jdbc:< dbtype>://ipaddress:portnumber/db_name"
  • <dbtype>- The driver for the database you are trying to connect. To connect to oracle database this value will be "oracle"
    For connecting to database with name "emp" in MYSQL URL will bejdbc:mysql://localhost:3036/emp
And the code to create connection looks like
Connection con = DriverManager.getConnection(dbUrl,username,password);
You also need to load the JDBC Driver using the code
Class.forName("com.mysql.jdbc.Driver");

2) Send Queries to the Database

Once connection is made, you need to execute queries.
You can use the Statement Object to send queries.
Statement stmt = con.createStatement();   
Once the statement object is created use the executeQuery method to execute the SQL queries
stmt.executeQuery(select *  from employee;);

3) Process the results

Results from the executed query are stored in the ResultSet Object.
Java provides loads of advance methods to process the results. Few of the methods are listed below
Database Testing using Selenium: Step by Step Guide

 Example of Database Testing with Selenium

понедельник, 16 апреля 2018 г.

AQA: Selenium + Java: Page Object Model



What it is? 
Page Object is a Design Pattern for enhancing test maintenance and reducing code duplication.
A page object is an object-oriented class that serves as an interface to a page of your AUT.
The tests then use the methods of this page object class whenever they need to interact with the UI of that page.

The benefit is?
- if the UI changes for the page, the tests themselves don’t need to change, only the
code within the page object needs to change;
- Subsequently all changes to support that new UI are located in one place;
- enchancing test maintenance;
- reducing code duplication;
- There is a clean separation between test code and page specific code such as locators (or their use if you’re using a UI Map) and layout;
- There is a single repository for the services or operations offered by the page rather than having these services scattered throughout the tests;

- In both cases this allows any modifications required due to UI changes to all be made in one place;

Summary: 
- The public methods represent the services that the page offers
- Try not to expose the internals of the page
- Generally don't make assertions
- Methods return other PageObjects
- Need not represent an entire page
- Different results for the same action are modelled as different methods

Links: 
- docs.seleniumhq.org;
- git - PageObjects;
- git - PageFactory;
- Михаил Поляруш - video:
- page-object-model;
- Introduction to Page Object Model Framework;
- Simple Page Object Model example;
- Оптимизация теста с помощью Page Object. Часть 1. Создание классов с описанием веб-страниц;
- Оптимизация теста с помощью Page Object. Часть 2. Создание теста;
- Применение Property файлов в автотестах на Java;
- Использование паттерна Page Object;
- Подготовка Page Object Model - пример на автоматизации ФБ;

вторник, 10 апреля 2018 г.

AQA: Java: Java 9 – Exploring the REPL

1. Introduction

This article is about jshell, an interactive REPL (Read-Evaluate-Print-Loop) console that is bundled with the JDK for the upcoming Java 9 release. For those not familiar with the concept, a REPL allows to interactively run arbitrary snippets of code and evaluate their results.
A REPL can be useful for things such as quickly checking the viability of an idea or figuring out e.g. a formatted string for String or SimpleDateFormat.

2. Running

To get started we need to run the REPL, which is done by invoking:
1
$JAVA_HOME/bin/jshell
If more detailed messaging from the shell is desired, a -v flag can be used:
1
$JAVA_HOME/bin/jshell -v
Once it is ready, we will be greeted by a friendly message and a familiar Unix-style prompt at the bottom.

3. Defining and Invoking Methods

Methods can be added by typing their signature and body:
1
2
jshell> void helloWorld() { System.out.println("Hello world");}
|  created method helloWorld()
Here we defined the ubiquitous “hello world” method.  It can be invoked using normal Java syntax:
1
2
jshell> helloWorld()
Hello world

4. Variables

Variables can be defined with the normal Java declaration syntax:
1
2
3
4
5
6
7
8
9
10
11
jshell> int i = 0;
i ==> 0
|  created variable i : int
 
jshell> String company = "Baeldung"
company ==> "Baeldung"
|  created variable company : String
 
jshell> Date date = new Date()
date ==> Sun Feb 26 06:30:16 EST 2017
|  created variable date : Date
Note that semicolons are optional.  Variables can also be declared without initialization:
1
2
3
jshell> File file
file ==> null
|  created variable file : File

5. Expressions

пятница, 6 апреля 2018 г.

AQA: Selenium - video collection

AQA: Selenium: Execute TestNg Project using batch file


Execute TestNg Project using batch file

Below description would help you to execute JAVA + TestNg Project using batch file.
Here, we have one sample class called SampleTest.java in JAVA Project which would open Google in chrome browser and verify the page title and then closes the browser at the end.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class SampleTest {
    WebDriver driver;
    @BeforeMethod
    public void setup() {
        String baseUrl = "http://www.google.com";
        // Initialize driver object
        System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "/lib/chromedriver.exe");
        driver = new ChromeDriver();
        // Launch Application on browser
        driver.get(baseUrl);
    }
    @Test
    public void test01() {
        String expectedPageTitle = "Google";
        String actualPageTitle = "";
        // Fetch page title and store it in a variable
        actualPageTitle = driver.getTitle();
        // Print title
        System.out.println(actualPageTitle);
        if (actualPageTitle.equals(expectedPageTitle)) {
            System.out.println("Test case passed");
        } else {
            System.out.println("Test case Failed");
        }
    }
    @AfterMethod
    public void tearDonw() {
        // close browser
        driver.close();
    }
}

SEO: Эксперимент: как Яндекс и Google учитывают ключевые слова в URL

Эксперимент: как Яндекс и Google учитывают ключевые слова в URL Эксперимент: как Яндекс и Google учитывают ключевые слова в URL Дата пу...