hi guys
I am new to selenium and I am using eclipse and webdriver. I have perfectly running test for firefox but I don't know how to remake it to work with IE ? Simply changing firefox driver to IE driver does not work what else should I change ? It will be best if someone can give me a simple example of a test that is able to run in IE. Here is some of my code as an example of what I am doing right now: import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriverBackedSelenium; import org.openqa.selenium.firefox.FirefoxDriver; import com.thoughtworks.selenium.SeleneseTestBase; public class fujitsu1 extends SeleneseTestBase { @Before public void setUp() throws Exception { WebDriver driver1 = new FirefoxDriver(); String baseUrl = "http://website.com/"; selenium = new WebDriverBackedSelenium(driver1, baseUrl); } @Test public void testFujitsu() throws Exception { selenium.setSpeed("50000"); String x = "409"; selenium.open("/login.php"); selenium.type("//*[@id='main-container']/table/tbody/tr/td/table/tbody/tr/td/div/form/div/p[1]/input", "username"); selenium.type("//*[@id='main-container']/table/tbody/tr/td/table/tbody/tr/td/div/form/div/p[2]/input", "password"); selenium.click("//a[text()='Login']"); selenium.waitForPageToLoad("30000"); for (int second = 0;; second++) { if (second >= 60) fail("timeout"); try { if (selenium.isElementPresent("//a[text()='Idee eingeben']")) break; } catch (Exception e) {} Thread.sleep(1000); } selenium.click("//a[text()='Idee eingeben']"); selenium.waitForPageToLoad("30000"); selenium.click("//*[@id='enteridea-form-question']/table/tbody/tr[11]/td/table/tbody/tr[1]/td[1]/input"); selenium.click("//*[@id='enteridea-form-question']/table/tbody/tr[13]/td/a"); for (int second = 0;; second++) { if (second >= 60) fail("timeout"); try { if (selenium.isElementPresent("//*[@id='enteridea-form-desc']/input[3]")) break; } catch (Exception e) {} Thread.sleep(1000); } |
Administrator
|
Hi zlos7ar,
Why are you using WebDriverBackedSelenium instead of using WebDriver method. WebDriverBackedSelenium does not emulate all Selenium methods correct. This post might help you in learning to use WebDriver API - http://www.seleniumtests.com/2012/01/selenium-2-methods-are-no-more-weird.html Just replace the FirefoxDriver with InternetExplorerDriver and you are good to use it.
~ seleniumtests.com
|
thanks for the help I hope that will work but can you tell me where I can find more information about the commands I can use ?
for example how do I find an element by text ? (driver.findElement(By.text("//span[text()='aaa']")).click(); does not work. and how can I use selenium.fireEvent ? |
it still does not work when I run the test with IE it just says "This is the initial start page for the WebDriver server." and nothing else happens... the same thing happens when I use webdriver backed
|
Administrator
|
Can you post your code when you used IE web driver and got to see message - ""This is the initial start page for the WebDriver server.""?
~ seleniumtests.com
|
I am using windows 7 and IE 9 and Eclipse but I think its the same on all IE browsers
Thats with webdriver backed but its the same with the one you suggested too Here is the code : import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriverBackedSelenium; import org.openqa.selenium.ie.InternetExplorerDriver; import com.thoughtworks.selenium.SeleneseTestBase; public class MoreAndSubmitIdea extends SeleneseTestBase { @Before public void setUp() throws Exception { WebDriver driver = new InternetExplorerDriver(); String baseUrl = "https://website.de/"; selenium = new WebDriverBackedSelenium(driver, baseUrl); } @Test public void testMoreAndSubmitIdea() throws Exception { selenium.open("/login.php"); selenium.type("name=login_user", "admin"); selenium.type("//*[@id='content-container']/div[1]/form/div[2]/div[2]/input", "password"); selenium.click("css=div.center > input[name=\"submit\"]"); selenium.waitForPageToLoad("30000"); for (int second = 0;; second++) { if (second >= 60) fail("timeout"); try { if (selenium.isElementPresent("//div[text()='mehr']")) break; } catch (Exception e) {} Thread.sleep(1000); } selenium.click("//div[text()='mehr']"); selenium.fireEvent("//div[text()='mehr']", "click"); for (int second = 0;; second++) { if (second >= 60) fail("timeout"); try { if (selenium.isElementPresent("//*[@id='ui-dialog-title-popup']")) break; } catch (Exception e) {} Thread.sleep(1000); } .......... ......... ............ @After public void tearDown() throws Exception { selenium.stop(); } } |
Administrator
|
Well you are again using Selenium API and not WebDriver API,
any way could you place complete URL of your application in this line - selenium.open("/login.php");
~ seleniumtests.com
|
nope it still does not work I am also trying with this code and the result is the same
import static org.junit.Assert.fail; import java.util.concurrent.TimeUnit; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.ie.InternetExplorerDriver; public class testing { private WebDriver driver; private String baseUrl; private StringBuffer verificationErrors = new StringBuffer(); @Before public void setUp() throws Exception { driver = new InternetExplorerDriver(); baseUrl = "https://reinhausen.my-ideanet.dolly.hyve.de/"; driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); } @Test public void testMoreAndSubmitIdea() throws Exception { driver.get(baseUrl + "/login.php"); driver.findElement(By.name("login_user")).clear(); driver.findElement(By.name("login_user")).sendKeys("admin"); driver.findElement(By.xpath("//*[@id='content-container']/div[1]/form/div[2]/div[2]/input")).clear(); driver.findElement(By.xpath("//*[@id='content-container']/div[1]/form/div[2]/div[2]/input")).sendKeys("password"); driver.findElement(By.cssSelector("div.center > input[name=\"submit\"]")).click(); for (int second = 0;; second++) { if (second >= 60) fail("timeout"); try { if (isElementPresent(By.xpath("//*[@id='content-container']/div[1]/div[9]/div[7]"))) break; } catch (Exception e) {} Thread.sleep(1000); } } ............. ............. ............... @After public void tearDown() throws Exception { driver.quit(); String verificationErrorString = verificationErrors.toString(); if (!"".equals(verificationErrorString)) { fail(verificationErrorString); } } private boolean isElementPresent(By by) { try { driver.findElement(by); return true; } catch (NoSuchElementException e) { return false; } } } |
That is the Eclipse error massage :
Apr 12, 2012 5:27:01 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute Information: I/O exception (java.net.SocketException) caught when processing request: Software caused connection abort: recv failed Apr 12, 2012 5:27:01 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute Information: Retrying request and in the browser I get a white screen with the massage "This is the initial start page for the WebDriver server." |
Administrator
|
In reply to this post by zlos7ar
Strange. Two stupid questions -
1. Could you try to launch URL manually in IE and see if that works? 2. When you don't see app being launched in IE then do you eventually encounter any exception? How long do you wait for application to launch. Also which version of Selenium jar are you using. I hope you are using selenium-server-standalone jar.
~ seleniumtests.com
|
You can read the errors in my previous post I gues we were writing at the same time and you didn't saw it.
Starting IE manually does not work. Even if I open IE it still opens a new window. I don't wait at all It starts immediately. I think I am using selenium server standalone 2.19.0. Could it be some security/permissions problem ? |
Administrator
|
This looks related to your error -
http://code.google.com/p/selenium/issues/detail?id=3515 Can you downgrade server to 2.13 and try. I use this jar and have not seen any issue, you can get it from - http://code.google.com/p/selenium/downloads/detail?name=selenium-server-standalone-2.13.0.jar&can=1&q=#makechanges try this and let us know how it goes
~ seleniumtests.com
|
thanks for the help I will try tomorrow when I get back to work and I will let you know.
|
good morning the issue is solved I just had to delete my selenium libraries and install only selenium-server-standalone and now it works perfectly thanks for the help again
|
By the way this is issue 2568 if you want to read more about it. I have posted my solution there. I hope it works for other people too :)
|
Administrator
|
Thanks for sharing your solution
~ seleniumtests.com
|
Free forum by Nabble | Edit this page |