Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
444 views
by The go-to Tester (324 points)
edited by

i am using "((RemoteWebDriver) driver).setFileDetector(new LocalFileDetector());", to upload an image on browserstack. it is working for 1st time but when i am using it twice in same class, then its showing an error for second time. Please help to resolve this problem.

Edit: Attaching the error screenshot:

by The go-to Tester (181 points)
can you post your code and also stack trace of the error you are facing?
by The go-to Tester (324 points)
@Test(priority=1)
    @Parameters({"userId","password","url"})
    public void testUpload(String userId,String password,String url) throws Exception
    {
       
//        String exePath = System.getProperty("user.dir") + "\\TestData\\chromedriver.exe";
//        System.setProperty("webdriver.chrome.driver", exePath);
       
          DesiredCapabilities caps = new DesiredCapabilities();
            caps.setCapability("browser", "Chrome");
            caps.setCapability("browser_version", "55.0");
            caps.setCapability("os", "Windows");
            caps.setCapability("os_version", "8");
            caps.setCapability("resolution", "1920x1080");
            WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
       
        action_obj = new Repo_Test(driver);
        Assertion_obj = new Assertion_Test(driver);
        executor=(JavascriptExecutor) driver;
        driver.get(url);
        System.out.println("---------------------------------------------------------------------------------------------------------------");
        //Open URL
        System.out.println("@URL Opening......."+url);
        //Maximize Window
        driver.manage().window().maximize();
        Thread.sleep(3000);
        //Click on 'Sign in with email' link
        action_obj.signin().click();
        Thread.sleep(1500);
        //Entering userID
        action_obj.username().sendKeys(userId);
        Thread.sleep(1000);
        //Entering Password
        action_obj.Password().sendKeys(password);
        //Click on 'LOGIN' button
        Thread.sleep(350);
        action_obj.loginbutton().click();
        Thread.sleep(500);
        //Assertion for Login
        Assertion_obj.logout_assertion();

        Thread.sleep(3000);
        //Entering data in status section
        action_obj.usercontentstatus().sendKeys("Classic Shortbread(Picture For test purpose)");
        Thread.sleep(1000);
       
        //Uploading file
       
        ((RemoteWebDriver) driver).setFileDetector(new LocalFileDetector());
        Thread.sleep(2000);
        driver.findElement(By.xpath(".//*[@id='content']/div[2]/div/div[2]/div/div/form/div/div/div[3]/div[1]/input")).sendKeys("C:\\Users\\hello\\Documents\\images\\wallpaper2.jpg");   
        Thread.sleep(2000);
        action_obj.postbutton().click();
       
        Thread.sleep(2000);
    }
   
   
    @Test(priority=2)
    public void Editing_Pictures_by_Business_User() throws Exception{
        //Again click on 'Home'
        action_obj.home().click();
        Thread.sleep(1000);
        //Scroll
        JavascriptExecutor jse = (JavascriptExecutor)driver;
        Thread.sleep(1000);
       
        //Click on Edit button
        action_obj.recipesedit().click();
        Thread.sleep(2000);
        //Edit Name
        action_obj.editname().sendKeys("Edited");
        Thread.sleep(2000);
        //Click on 'OK' button
        Thread.sleep(500);
        action_obj.editdecok().click();
        //Assertion
        Assertion_obj.edit_assertion();
        Thread.sleep(2000);
    }
    @Test(priority=3)
    public void Deleting_Pictures_Contents_by_Business_User() throws Exception{
        //Click on 'Delete' button
        action_obj.editdelete().click();
        Thread.sleep(500);
//        Assertion_obj.edit_delete_pic();
//        String act_deletetext = action_obj.recipesedit().getText();
//        Thread.sleep(300);
//        String Ex_deletetext = "Classic Shortbread(Picture For test purpose)Edited";
//        Assert.assertNotEquals(act_deletetext,Ex_deletetext);   

               
}
    @Test(priority=4)
    public void Posting_Video_By_Business_User() throws Exception{
       
        Thread.sleep(2000);
        //Entering data in status section
        action_obj.usercontentstatus().sendKeys("Classic Shortbread(Video For test purpose)");
        Thread.sleep(2000);
        //Uploading file
       
       
        ((RemoteWebDriver) driver).setFileDetector(new LocalFileDetector());
        Thread.sleep(2000);
        driver.findElement(By.xpath(".//*[@id='content']/div[2]/div/div[2]/div/div[1]/form/div/div/div[3]/div[2]/input")).sendKeys("C:\\Users\\hello\\Documents\\video\\sample_mpeg4.mp4");   
        Thread.sleep(2000);
       
        //Scroll
        JavascriptExecutor jse = (JavascriptExecutor)driver;
        jse.executeScript("window.scrollBy(0,500)", "");
        Thread.sleep(1000);
        //Click on Post button
        action_obj.postbutton().click();
        Thread.sleep(700);
        //Assertion
        Assertion_obj.addpost();
    }
by The go-to Tester (181 points)
also post your stacktrace
by The go-to Tester (324 points)

1 Answer

1 like 0 dislike
by The go-to Tester (181 points)
selected by
 
Best answer

You are declaring and defining new driver instance at function level for the first function.

WebDriver driver = new RemoteWebDriver(new URL(URL), caps);

It looks like you have another driver declared at class level. So you should use that. So your code should be as below.

this.driver = new RemoteWebDriver(new URL(URL), caps);

Hope that helps!


 

by The go-to Tester (324 points)
Thank You so much sir, it's working!! :-)


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...