0

I am a new learner to Selenium and its frameworks, need help in the following:

I had used set property as shown below in Program 1 as i was facing issues while sending keys. The keys were being sent very slow, but by using setProperty the issue was solved.

However when I split this code for testing as in Program 2, the keys are sent slow in spite of setting the property. Is there anything wrong in how I am setting it?

Program 1

public class BAU{

    public static void main(final String[] args) throws interruptedException{

        System .setProperty("webdriver.ie.driver","C:\\Selenium-Internet Explorer Driver Server v2.48.0(for 32 bit Windows IE)\\Selenium-Internet Explorer Driver Server v2.48.0(for 32 bit Windows IE)\\IEDriverServer.exe");
        WebDriver drive = new InternetExplorerDriver();
        drive.get("https:/testlogin.html");
        drive.manage().window().maximize();
        Thread.sleep(500);
        drive.findElement(By.name("i_username")).sendKeys("Abcde");
        drive.findElement(By.name("i_password")).sendKeys("Pass");
        this.drive.findElement(By.className("btnPrimary")).click();
    }
}

Program 2

public class BAU_TESTING{

    @Test(priority = 1)
    public void setProperty(){

        System .setProperty("webdriver.ie.driver","C:\\Selenium-Internet Explorer Driver Server v2.48.0(for 32 bit Windows IE)\\Selenium-Internet Explorer Driver Server v2.48.0(for 32 bit Windows IE)\\IEDriverServer.exe");
    }

    WebDriver drive = new InternetExplorerDriver();

    @Test(priority = 2)
    public void launchBrowser() throws InterruptedException {

        this.drive.get("https:/testlogin.html");
        this.drive.manage().window().maximize();
        Thread.sleep(500);
        System.out.println("Test Case 1 for launching the page has been executed");
    }

    @Test(priority = 3)

    public void loginPage() throws InterruptedException {

        this.drive.findElement(By.name("i_username")).sendKeys("Abcde");
        this.drive.findElement(By.name("i_password")).sendKeys("Pass");
        this.drive.findElement(By.className("btnPrimary")).click();
    }
}
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
siby21t
  • 11
  • 1
  • 5

1 Answers1

0

I would suggest you to put setProperty(), opening of the page and other common actions in a separate class file and then accessing those classes whenever you need in different tests. As an example you can put your browser setting and url opening method in this way.

`public class Browser {

static WebDriver  driver;

public static WebDriver launchApp(String browser, String URL) {

    if (browser.equals("firefox")) {

        driver = new FirefoxDriver();
    }
    else if (browser.equals("chrome")) {

        driver = new ChromeDriver();
        driver.navigate().to(URL);
    }else if (browser.equals("ie")){

        System.setProperty("webdriver.ie.driver", "C:\\Softwares\\Drivers\\"+"IEDriverServer.exe");
        WebDriver driver = new InternetExplorerDriver();
        driver.navigate().to(URL);
    }

    return driver;
}

}`

And Create a seperate class to call those browser and run your test.

`public class testGoogleSearch {


@Test
public void testLaunchApp() {
    WebDriver driver = Browser.launchApp("chrome","https://www.google.com");

    System.out.println("search something");
    driver.findElement(By.id("lst-ib")).sendKeys("Selenium");

    driver.findElement(By.name("btnK")).click();
}

}`

Good Luck!!

PJAutomator
  • 344
  • 3
  • 12
  • I wont be using chrome but only ie ,as the browser i am using is compatible only with ie so calling separate classes for different browsers wont be helpful..any other way that i can set 'setproperty' global and it would work for all send keys. – siby21t Jun 11 '18 at 04:04
  • @siby21t you can extend the class you are creating setProperty/driver and then use thatin the different test classes where you want to make use of driver. That will only make your code cleaner and reusable. – PJAutomator Jun 11 '18 at 19:35