t.me/atinfo_chat Telegram группа по автоматизации тестирования

Настройка Jenkins для Java-Selenium Webdriver-Junit

serenity
infrastructure
jenkins
java
junit
Теги: #<Tag:0x00007f9c4ab72850> #<Tag:0x00007f9c4ab726c0> #<Tag:0x00007f9c4ab72558> #<Tag:0x00007f9c4ab72418> #<Tag:0x00007f9c4ab722d8>

(Олег Капустин) #1

Может ли кто-либо подсказать в настройке Junit. Дальше этого не идет


(Vasiliy Rakshin) #2

Что, даже никаких ошибок не появляется? Вот так всё висит виснем?


(Дмитрий Еремин) #3

А вы видите браузер где-то? Там тест проходит?
Пока больше похоже, что дело не в jUnit, а в том, чтобы поднять драйвер


(Олег Капустин) #4

Нет, ничего не происходит. Только вот этот экран. Браузер тоже не отображается. Может нет доступа к интерфейсу


(Vasiliy Rakshin) #5

Вижу локалхост, скорее всего дженкинс запущен как сервис, браузер и не увидите.

  1. Надо браузер запускать в хеадлесс режиме.
  2. Версия хромдрайвера 73, хрома такая же?
  3. Надо точное сообщение ошибки.

(Олег Капустин) #6

Вот .xml файл. Может что-то лишнее?
Java-Selenium Webdriver-Junit

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <groupId>cyberClaims_project</groupId>
    <artifactId>cyberClaims_project</artifactId>
    <version>3.0</version>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M3</version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>3.0.0-M3</version>
                <configuration>
                    <parallel>methods</parallel>
                    <threadCount>10</threadCount>
                </configuration>
            </plugin>


        </plugins>
    </build>

    <dependencies>
        <!--  https://mvnrepository.com/artifact/junit/junit  -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <!--
         https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java
        -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.11.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.testng/testng -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.0.0-beta4</version>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>4.0.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>4.0.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.aventstack/extentreports -->
        <dependency>
            <groupId>com.aventstack</groupId>
            <artifactId>extentreports</artifactId>
            <version>4.0.9</version>
        </dependency>

        <dependency>
            <groupId>io.appium</groupId>
            <artifactId>java-client</artifactId>
            <version>5.0.4</version>
        </dependency>

        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.0.0-M3</version>
            <type>maven-plugin</type>
        </dependency>

    </dependencies>



</project>

(Дмитрий Еремин) #7

И TestNG и jUnit? Не в этом проблема, просто интересно

А дженкинс на чем крутится? На винде какой-то и у вас линукс без графической оболочки?
Если никакого GUI нет, то никаког браузера и ждать не стоит. Выход или headless-браузер или Selenoid
Рекомендую потратить полдня и настроить запуск в контейнерах - https://aerokube.com/selenoid/latest/


(Vasiliy Rakshin) #8

Старый selenium-java, надо использовать свежую версию.


(Олег Капустин) #9

Нет.
А какие вообще зависимости должы быть в pom.xml?
Не подскажите как настроить headless-браузер или Selenoid


(Олег Капустин) #10
Started by user Капустин Олег
Building in workspace C:\Program Files (x86)\Jenkins\workspace\CyberClaims
Parsing POMs
Established TCP socket on 57464
[cyberClaims_project] $ "c:\Program Files\Java\jdk-11.0.2/bin/java" -cp "C:\Program Files (x86)\Jenkins\plugins\maven-plugin\WEB-INF\lib\maven35-agent-1.12.jar;c:\Program Files\Maven\boot\plexus-classworlds-2.5.2.jar;c:\Program Files\Maven/conf/logging" jenkins.maven3.agent.Maven35Main "c:\Program Files\Maven\" "C:\Program Files (x86)\Jenkins\war\WEB-INF\lib\remoting-3.29.jar" "C:\Program Files (x86)\Jenkins\plugins\maven-plugin\WEB-INF\lib\maven35-interceptor-1.12.jar" "C:\Program Files (x86)\Jenkins\plugins\maven-plugin\WEB-INF\lib\maven3-interceptor-commons-1.12.jar" 57464
<===[JENKINS REMOTING CAPACITY]===>channel started
Executing Maven:  -B -f E:\SoftwareTesting\cyberClaims_project\pom.xml install
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------< cyberClaims_project:cyberClaims_project >---------------
[INFO] Building cyberClaims_project 3.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ cyberClaims_project ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ cyberClaims_project ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ cyberClaims_project ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory E:\SoftwareTesting\cyberClaims_project\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ cyberClaims_project ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ cyberClaims_project ---
[INFO] Surefire report directory: E:\SoftwareTesting\cyberClaims_project\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running net.iveLogik.claimsStaging.tests.FirstTest
Starting ChromeDriver 73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72) on port 22344
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
апр. 09, 2019 1:30:02 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
[1554806403.458][SEVERE]: Timed out receiving message from renderer: 600.000
[1554806703.458][SEVERE]: Timed out receiving message from renderer: 300.000
[1554807303.459][SEVERE]: Timed out receiving message from renderer: 600.000
[1554807303.459][SEVERE]: Timed out receiving message from renderer: -600.001
Starting ChromeDriver 73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72) on port 15676
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
апр. 09, 2019 1:55:05 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS

(Дмитрий Еремин) #11

настройка селеноид - https://aerokube.com/selenoid/latest/#_quick_start_guide


(Юрий Палазенюк) #12

(Sheff) #13
	WebDriver driver;
	ChromeOptions ChromeOptions = new ChromeOptions();
	ChromeOptions.addArguments("--headless", "window-size=1024,768", "--no-sandbox"); // Параметр "--headless" отвечает за запуск "безголового" хрома
	driver = new ChromeDriver(ChromeOptions);

(Олег Капустин) #14

Спасибо. Теперь это выглядит следующим образом:

Building in workspace C:\Program Files (x86)\Jenkins\workspace\CyberClaims
Parsing POMs
Modules changed, recalculating dependency graph
Established TCP socket on 64300
[cyberClaims_project] $ "c:\Program Files\Java\jdk-11.0.2/bin/java" -cp "C:\Program Files (x86)\Jenkins\plugins\maven-plugin\WEB-INF\lib\maven35-agent-1.12.jar;c:\Program Files\Maven\boot\plexus-classworlds-2.5.2.jar;c:\Program Files\Maven/conf/logging" jenkins.maven3.agent.Maven35Main "c:\Program Files\Maven\" "C:\Program Files (x86)\Jenkins\war\WEB-INF\lib\remoting-3.29.jar" "C:\Program Files (x86)\Jenkins\plugins\maven-plugin\WEB-INF\lib\maven35-interceptor-1.12.jar" "C:\Program Files (x86)\Jenkins\plugins\maven-plugin\WEB-INF\lib\maven3-interceptor-commons-1.12.jar" 64300
<===[JENKINS REMOTING CAPACITY]===>channel started
Executing Maven:  -B -f E:\SoftwareTesting\cyberClaims_project\pom.xml install
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------< cyberClaims_project:cyberClaims_project >---------------
[INFO] Building cyberClaims_project 3.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ cyberClaims_project ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ cyberClaims_project ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ cyberClaims_project ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory E:\SoftwareTesting\cyberClaims_project\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ cyberClaims_project ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:3.0.0-M3:test (default-test) @ cyberClaims_project ---
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running net.iveLogik.claimsStaging.tests.FirstTest
Starting ChromeDriver 74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}) on port 47023
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.724 s <<< FAILURE! - in net.iveLogik.claimsStaging.tests.FirstTest
[ERROR] T(net.iveLogik.claimsStaging.tests.FirstTest)  Time elapsed: 2.528 s  <<< ERROR!
org.openqa.selenium.SessionNotCreatedException: 
session not created: This version of ChromeDriver only supports Chrome version 74
  (Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Windows NT 10.0.17763 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 663 milliseconds
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:26:55.152Z'
System info: host: 'DESKTOP-ON5CNMT', ip: '192.168.1.104', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.2'
Driver info: driver.version: ChromeDriver

[INFO] 
[INFO] Results:
[INFO] 
[ERROR] Errors: 
[ERROR]   FirstTest>WebDriverSettings.setUp:48 » SessionNotCreated session not created: ...
[INFO] 
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
[INFO] 
[ERROR] There are test failures.

Please refer to E:\SoftwareTesting\cyberClaims_project\target\surefire-reports for the individual test results.
Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[JENKINS] Recording test results
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.dom4j.io.SAXContentHandler to method com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser$LocatorProxy.getEncoding()
WARNING: Please consider reporting this to the maintainers of org.dom4j.io.SAXContentHandler
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[WARNING] Attempt to (de-)serialize anonymous class hudson.maven.reporters.SurefireArchiver$2; see: https://jenkins.io/redirect/serialization-of-anonymous-classes/
[WARNING] Attempt to (de-)serialize anonymous class hudson.maven.reporters.BuildInfoRecorder$1; see: https://jenkins.io/redirect/serialization-of-anonymous-classes/
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ cyberClaims_project ---
[INFO] Building jar: E:\SoftwareTesting\cyberClaims_project\target\cyberClaims_project-3.0.jar
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ cyberClaims_project ---
[INFO] Installing E:\SoftwareTesting\cyberClaims_project\target\cyberClaims_project-3.0.jar to C:\Windows\system32\config\systemprofile\.m2\repository\cyberClaims_project\cyberClaims_project\3.0\cyberClaims_project-3.0.jar
[INFO] Installing E:\SoftwareTesting\cyberClaims_project\pom.xml to C:\Windows\system32\config\systemprofile\.m2\repository\cyberClaims_project\cyberClaims_project\3.0\cyberClaims_project-3.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  14.765 s
[INFO] Finished at: 2019-04-15T23:18:18+03:00
[INFO] ------------------------------------------------------------------------
Ожидаю пока Jenkins закончит сбор данных
[JENKINS] Archiving E:\SoftwareTesting\cyberClaims_project\pom.xml to cyberClaims_project/cyberClaims_project/3.0/cyberClaims_project-3.0.pom
[JENKINS] Archiving E:\SoftwareTesting\cyberClaims_project\target\cyberClaims_project-3.0.jar to cyberClaims_project/cyberClaims_project/3.0/cyberClaims_project-3.0.jar
channel stopped
Finished: UNSTABLE

(Олег Капустин) #15
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <groupId>cyberClaims_project</groupId>
    <artifactId>cyberClaims_project</artifactId>
    <version>3.0</version>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <groupId>org.apache.maven.plugins</groupId>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M3</version>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <!--  https://mvnrepository.com/artifact/junit/junit  -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <!--
         https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java
        -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.11.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
        </dependency>

        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.0.0-M3</version>
            <type>maven-plugin</type>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-chrome-driver -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-chrome-driver</artifactId>
            <version>3.141.59</version>
        </dependency>
        
    </dependencies>
</project>

(Олег Капустин) #16
package net.iveLogik.claimsStaging.tests;

import net.iveLogik.claimsStaging.VariablesAndMethods;
import org.junit.*;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.io.File;
import java.io.IOException;

public class WebDriverSettings implements VariablesAndMethods {

    public static WebDriver driver;
    public static WebDriverWait wait;
    private static ChromeDriverService service;


    @Before
    public void setUp() throws InterruptedException {

        ChromeOptions ChromeOptions = new ChromeOptions(); //1
        ChromeOptions.addArguments("--headless", "window-size=1024,768", "--no-sandbox"); //1
         
        driver = new ChromeDriver(ChromeOptions); 
     

        //создаем драйвер по времени ожидания
        wait = new WebDriverWait(driver, 20, 200);

        //открытие браузера и авторизация
        driver.get(URL);
        driver.findElement(By.xpath("//*[@id=\"email\"]")).sendKeys(SUPER_TENANT_USER);
        driver.findElement(By.xpath("//*[@id=\"password\"]")).sendKeys(STU_PASSWORD);
        driver.findElement(By.cssSelector("button[type='submit']")).sendKeys(Keys.RETURN);
        Thread.sleep(2000);
        Assert.assertTrue(driver.getCurrentUrl().equals("https://claims-staging.livelogik.net/"));

    }

    @After
    public void cleanUp() {

        // для закрытия сайта используем следующий код
        if (driver != null) {
            driver.quit();
        }

    }
   
}

(Sheff) #17


Пишут, что надо предыдущую версию хромдрайвера поставить