TestNG with several Classe

I have an issue with executing a TestNG File with several classes

<?xml version="1.0" encoding="UTF-8"?>
<test name="Device1">
     <parameter name="device_id" value="04157df4ec790621"/>
    <parameter name="device_name" value="samsung"/>
    <parameter name="platformVersion" value="6.0.1"/>
    <parameter name="platformName" value="Android"/>

        <class name="scenarios.Activation">
            <methods><include name="testActivationFlow"/></methods>
        <class name="scenarios.MenuAfterActivation">
            <methods><include name="testTransactionHistory"/></methods>   
        </class>   </classes>   </test> </suite>

I have a setup class which initiates the appiumserver and the webdriver. This method is annotated with @BeforeTest

I use pageobject model with different classes for each page and different classes for my scenario’s.

My Scenarioclasses extend the Setup Class.

When I execute the SetupClass, the methods from the first class are executed fine. But it fails when starting the methods froms the second class because the driver = null.

I can fix it for one device by making my driver static, but then I can’t execute parallell testing anymore.

I can also fix it by using @BeforeClass for my setup method, but than a new webdriver is initiated for each class. I don’t want this, since I want to execute al my tests on the same cloud device.

Someone knows how this can be fixed or any tips ?

@ManDD move start drive to “beforeMethod” and quit to “afterMethod”. also add logs to see that you are starting and closing driver. Also add logs in all “beforeXXXX” and “afterXXX” methods so you can clear see what happens.

example of mine logs:

TestNG] Running:
   kill Appium server
   start Appium server
 start appium as: [appium, --log-level, error, --port, 4725, --bootstrap-port, 5725, --command-timeout, 180, --session-override, --log-timestamp]
  appium server started
BeforeMethod: XXXXXXXXXXXXXXXX with arguments: 
   DRIVER start...
getDriver() - devicePlatform: android fastReset, runDestination: Local, deviceName: LGH8155e9892e6, serverID: 1, appiumServer_Port: 4725
Capabilities [{app=/Users/Aleksei/Downloads/test_clients/zzzzzzz.apk, noReset=false, clearSystemFiles=true, appWaitActivity=ee.zzzzzz.*, disableAndroidWatchers=true, version=, deviceName=LGH8155e9892e6, fullReset=false, platform=ANDROID, automationName=Appium, browserName=android, autoGrantPermissions=true, udid=LGH8155e9892e6, platformName=Android}]

If i put driver initiation in @beforemethod then for every method a new driver is initiated. If i do that on cloud device server, for all @test a new device is used.

I want that all methods and classes are executed on the same driver.

@ManDD Imaging you have 5 tests and all using same driver. Now each test can leave client on it own screen. More over if test fail this scren can be more random. How you going to start each test from random screen?

I don’t want to discuss about the aproach.

I just wonder why I can’t use the driver initiated in the @BeforeTest method.

Anyone else who knows a solution or want to check my code ?