executar.Executar.java Source code

Java tutorial

Introduction

Here is the source code for executar.Executar.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package executar;

import java.awt.List;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import roteiros.RoteiroAbaBackup;
import roteiros.RoteiroTeste;
import scriptauxiliares.Logout;
import slack.SlackApi;
import slack.SlackMessage;
import testcases.CasoTeste;
import util.Slack;

/**
 *
 * @author u0181181
 */
public class Executar implements Runnable {

    private WebDriver driver;
    private Integer codigoExecucao;
    private ArrayList<RoteiroTeste> listagemRoteiros;

    public Executar() {
        listagemRoteiros = new ArrayList<>();
        listagemRoteiros.add(new RoteiroAbaBackup());
    }

    public void executar() {

        codigoExecucao = 1; //BUCAR DO BANCO DE DADOS

        criarLogExecucao();

        new Thread(this).start();
    }

    @Override
    public void run() {

        try {

            System.setProperty("webdriver.chrome.driver", "C:\\AutomatedTestsDA\\chromedriver.exe");
            System.setProperty("webdriver.gecko.driver", "C:\\AutomatedTestsDA\\geckodriver.exe");

            DesiredCapabilities capabilities = DesiredCapabilities.chrome();
            capabilities.setCapability("marionette", true);
            driver = new ChromeDriver(capabilities);
            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
            driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);

            for (RoteiroTeste r : listagemRoteiros) {
                new ExecutarRoteiro(r, driver).executar();
            }
        } catch (Exception ex) {
            new Slack().sendMsgExecucaoIniciada("Erro na execuo da monitoria", ex.getMessage());
        } finally {
            try {
                new Logout(driver).realizarLogout();
                Thread.sleep(5000);
            } catch (Exception ex) {
                Logger.getLogger(Executar.class.getName()).log(Level.SEVERE, null, ex);
            }
            driver.close();
            driver.quit();
        }
    }

    private void criarLogExecucao() {

        //INSERI NOVA LINHA DA EXECUCAO

        for (RoteiroTeste r : listagemRoteiros) {
            //ADICIONA A LINHA DO ROTEIRO NO BANCO DE DADOS
            for (CasoTeste c : r.getListagemCasosTestes()) {
                //ADICIONA A LINHA DO CASO DE TESTE NO BANCO DE DADOS
            }
        }

    }

}