selenium.UnsupportedCommandException: the requested resource could not be found, or a request

4.3k Views Asked by At

getting exception FAILED CONFIGURATION: @AfterClass tearDown "org.openqa.selenium.UnsupportedCommandException: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource"

enter code here

public class BaseClass {
//read config file and initiate variables
ReadConfig readConfig = new ReadConfig();
public String username = readConfig.getUserName();
//public String password = "asas";
public String password = readConfig.getPassword();


public static AppiumDriver driver;
public static org.apache.logging.log4j.Logger logger;


@BeforeClass
public void setUp ()
{
    
    try {
        
    logger = LogManager.getLogger(BaseClass.class);
    
    DesiredCapabilities dc = new DesiredCapabilities();
    dc.setCapability(MobileCapabilityType.DEVICE_NAME, "bd178829");
    dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
    dc.setCapability(MobileCapabilityType.APP, "D:\\automation\\CRMNextMobileAutomation\\src\\test\\resources\\apps\\CRMNextNative 6.29.0-release_screenshot_enabled.apk");
    dc.setCapability("automationName","UiAutomator2");
    dc.setCapability("appPackage", "com.crmnextmobile.crmnextofflineplay");
    dc.setCapability("appActivity", "com.crmnextmobile.crmnextofflineplay.qr.QrScannerActivity");
    dc.setCapability("enforceAppInsall", true);

    URL url = new URL("http://127.0.0.1:4723/wd/hub");
    
    driver = new AppiumDriver(url,dc);
    driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
    
    System.out.println("CRMNext automation start..");
    driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
    
    //Clicking on Allow option on open permission pop up
    //driver.findElement(By.id("com.android.permissioncontroller:id/permission_allow_button")).click();
    
    if(!driver.findElements(By.id ("com.android.permissioncontroller:id/permission_allow_button")).isEmpty()){
        //THEN CLICK ON THE SUBMIT BUTTON
        System.out.println("permission_allow_button is found on page");
        driver.findElement(By.id("com.android.permissioncontroller:id/permission_allow_button")).click();
    }else{
        //DO SOMETHING ELSE AS SUBMIT BUTTON IS NOT THERE
        System.out.println("permission_allow_button not found on page");
    }
    
    //Clicking on Allow button of run in background pop up
    //driver.findElement(By.id("android:id/button1")).click();
    if(!driver.findElements(By.id ("android:id/button1")).isEmpty()){
        //THEN CLICK ON THE SUBMIT BUTTON
        System.out.println("button1 is found on page");
        driver.findElement(By.id("android:id/button1")).click();
    }else{
        //DO SOMETHING ELSE AS SUBMIT BUTTON IS NOT THERE
        System.out.println("button1 not found on page");
    }
    
    
    driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
    Thread.sleep(5000);
    
    System.out.println("CRMNext automation Before Skip..");
    //Clicking on Skip button
    driver.findElement(By.id("com.crmnextmobile.crmnextofflineplay:id/skip")).click();
    
    System.out.println("CRMNext automation after Skip..");
    driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
    
    Thread.sleep(10000);
    
    driver.findElement(By.id("com.crmnextmobile.crmnextofflineplay:id/relative_layout_continue")).click();
    Thread.sleep(2000);
    
    
    
    } catch (Exception exp) {
        // TODO: handle exception
        System.out.println("Cause is :"+exp.getCause());
        System.out.println("Message is :"+exp.getMessage());
        exp.printStackTrace();
    }

}

@Test
public void sample() {
    System.out.println("Sample run");
}


@AfterClass
public void tearDown()
{

    driver.close();
    driver.quit();
    
}

//org.openqa.selenium.UnsupportedCommandException: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource

all tests are failing due to this.

1

There are 1 best solutions below

0
Mat On

driver.close()

The driver.close() command is used to close the current browser window having focus. In case there is only one browser open then calling driver.close() quits the whole browser session.

Usability

Use driver.close() when dealing with multiple browser tabs or windows e.g. when clicking on a link that opens another tab. In this case after performing required action in the new tab, to close the tab, call the driver.close() method.

driver.quit()

The driver.quit() is used to quit the whole browser session along with all the associated browser windows, tabs and pop-ups.

Usability

Use driver.quit() when no longer want to interact with the driver object along with any associated window, tab or pop-up. Generally, it is the last statements of the automation scripts. Call driver.quit() in the @AfterClass method to close it at the end of the whole suite.

Use following code in @AfterClass

@AfterClass
public void tearDown()
{

   if (driver != null)
      driver.Quit();
    
}