vendredi 26 mai 2017

Java Selenium pararel test cases running

Can not run TC in parallel. I set up parallel TC running in testng.xml file. It opens 4 instances of browser but test cases are failed. Looks like it creates just one instance of browser session (or something like that) so it tries to do all 4 test in one instance.

How to modify my settings to run TCs in parallel successfully?

I have set up driver in the following way:

package MainSettings;

import Pages.StartPage;
//import TrackReporting.CaptureScreenShotOnFailureListener;
import TrackReporting.LoggingEventListener;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.events.EventFiringWebDriver;
import org.openqa.selenium.support.events.WebDriverEventListener;
import org.testng.annotations.*;

/**
 * Created by serhii.kaihorodov on 1/4/2016.
 */
//@Listeners(CaptureScreenShotOnFailureListener.class)
public class Settings {
    protected static WebDriver driver;
    protected String baseURL = "https://www.ukr.net";
    private static final WebDriverEventListener eventListener = new LoggingEventListener();
    protected StartPage mainPage;

    @BeforeMethod
    public void setUp()
    {
        System.setProperty("webdriver.chrome.driver", "D:\\Programming\\Java Automation\\ukr.net_test_cases-master\\chromedriver.exe");
//        driver = new EventFiringWebDriver(new FirefoxDriver()).register(eventListener);
        driver = new EventFiringWebDriver(new ChromeDriver()).register(eventListener);
        getDriver().get(baseURL);
        mainPage = new StartPage();
        driver.manage().window().maximize();
    }

    @AfterMethod
    public void tearDown()
    {
        driver.quit();
    }

    public static WebDriver getDriver()
    {
        return driver;
    }
}

My testng.xml file is the following:

<!DOCTYPE suite SYSTEM "http://ift.tt/19x2mI9" >

<suite name="My_auto_test" verbose="2" parallel="methods" thread-count="4">

    <test name="ukr.net">
        <classes>
            <class name="TestCases.TestCases_block_1"/>
        </classes>
    </test>

</suite>

pom file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://ift.tt/IH78KX"
         xmlns:xsi="http://ift.tt/ra1lAU"
         xsi:schemaLocation="http://ift.tt/IH78KX http://ift.tt/VE5zRx">
    <modelVersion>4.0.0</modelVersion>
    <groupId>MySel20Proj</groupId>
    <artifactId>MySel20Proj</artifactId>
    <version>1.0</version>
    <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.3.1</version>
        </dependency>

        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.9.6</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.9.8</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.20</version>
                    <configuration>
                        <parallel>tests</parallel>
                        <threadCount>4</threadCount>
                        <suiteXmlFiles>
                            <suiteXmlFile>KayTC/src/testng.xml</suiteXmlFile>
                        </suiteXmlFiles>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

My several test cases are:

package TestCases;

import MainSettings.Settings;
import org.testng.annotations.Test;

import java.io.IOException;

/**
 * Created by serhii.kaihorodov on 1/4/2016.
 */
public class TestCases_block_1
{
    public class TestCases extends Settings
    {
        @Test (priority=0)
        public void login()
        {
            mainPage.login("kay444415@ukr.net", "06011988");
        }

        @Test (priority=0)
        public void sinoptik_link_is_present1()
        {
            mainPage.login("kay444415@ukr.net", "06011988").sinoptik_link_is_present();
        }

        @Test (priority=0)
        public void autosale_link_is_present1()
        {
            mainPage.login("kay444415@ukr.net", "06011988").autosale_link_is_present();
        }
  }

Aucun commentaire:

Enregistrer un commentaire