appium / java-client

Java language binding for writing Appium Tests, conforms to W3C WebDriver Protocol
Apache License 2.0
1.18k stars 752 forks source link

@parameters anonation through exception"BeforeSuite on method initializeAndroidDriver but has not been marked @Optional or defined" #2100

Closed asmayonis1 closed 5 months ago

asmayonis1 commented 5 months ago

Do I have the most recent component updates?

Is the component officially supported by the Appium team?

Is there an existing issue for this?

Current Behavior

@BeforeSuite @Parameters({"platformVersion", "platformName", "deviceName", "automationName"}) public void initializeAndroidDriver( String platformVersion, String platformName, String deviceName, String automationName) throws MalformedURLException { {

    URL url = new URL("http://127.0.0.1:4723");
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("appium:platformVersion", platformVersion);
    capabilities.setCapability("appium:platformName", platformName);
    capabilities.setCapability("appium:deviceName", deviceName);
    capabilities.setCapability("appium:automationName", automationName );
    capabilities.setCapability("appPackage", "com.talabat");
    capabilities.setCapability("appActivity", "com.talabat.LandingScreen");
    capabilities.setCapability("appium:locationServicesAuthorized", false);
    capabilities.setCapability("appium:locationServicesEnabled", false);
    capabilities.setCapability("appium:autoDismissAlerts", true);
    capabilities.setCapability("appium:autoAcceptAlerts", false);

    androidDriver = new AndroidDriver(url, capabilities);
    wait = new WebDriverWait(androidDriver, Duration.ofSeconds(50));
}
}

and run testng xml file 
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

through exception org.testng.TestNGException: Parameter 'platformVersion' is required by BeforeSuite on method initializeAndroidDriver but has not been marked @Optional or defined in /private/var/folders/b5/936632353fj08k51cf78vm9jcn4crr/T/testng-eclipse-1114858715/testng-customsuite.xml

Expected Behavior

Android parameters should read from XML and run correctly

Minimal Reproducible Example

code has been attached

Environment

Link to Appium Logs

No response

Further Information

No response

mykola-mokhnach commented 5 months ago

Not sure this exception has to do anything with this client

amedvedjev commented 5 months ago

eeee. 1 you should move start Appium driver to @beforeMethod 2 this is not an appium bug. ask questions -> https://discuss.appium.io/ 3 error tells: you did not provide platformVersion you can add logs to see it:

    public void initializeAndroidDriver(
            String platformVersion,
            String platformName,
            String deviceName,
            String automationName) throws MalformedURLException {
        System.out.println("initializeAndroidDriver(): platformVersion: '" + platformVersion + "', platformName: '" + platformName + "', deviceName: '" + deviceName + "', automationName: '" + automationName + "'");
asmayonis1 commented 5 months ago

@amedvedjev platform provided in XML as

<test name="Test-OnePlus5">
        <parameter name="platformVersion" value="13.0"></parameter>
        <parameter name="platformName" value="android"></parameter>
        <parameter name="deviceName" value="RF8NA0W2YFM"></parameter>
        <parameter name="automationName" value="UiAutomator2" />

but I figured the issue is we need to import import org.testng.ITestContext;