So I used the Selenium IDE to create a test case for some automation that I want to do. I want to be able to create some kind of loop / flow control for this case, so I decided that I would need to export it from the Selenium IDE to something like Java (I'm most familiar with Java). I exported to Java / JUnit4 / Web Driver . I think that trying to execute a java file through Eclipse will work best, although if someone knows something easier let me know. Anyway, I havenโt found NO GOOD DEVELOPMENT on how to run this Java through Eclipse.
In most of the cases I read, tell me to make sure my Path Path libraries contain a standalone Selenium server . Pretty much everything I read tells me to use Selenium Remote Control. However, I thought RC was worthless, and I wonder if there is a way to make it work with the newer web driver materials that I downloaded from Selenium. Also, most of the things I read tell me that I need to use public static void main () , which is a bit inconvenient because I donโt know how to change the code that exported selenium gives me (obviously, I can't just paste all this into the main method).
If anyone could get me through exporting Selenium to Java to execute code, I will be forever in your debt.
Selenium code gives me: package com.example.tests;
package com.rackspace; import java.util.concurrent.TimeUnit; import org.openqa.selenium.Alert; import org.openqa.selenium.By; import org.openqa.selenium.NoAlertPresentException; import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.Select; public class RackspaceContactAutomation { private WebDriver driver; private String baseUrl; private boolean acceptNextAlert = true; private StringBuffer verificationErrors = new StringBuffer(); @Before public void setUp() throws Exception { driver = new FirefoxDriver(); baseUrl = "https://cp.rackspace.com/Exchange/Mail/Contacts/List.aspx?selectedDomain=blahblahblah.com"; driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); } @Test public void testContactAutomationJava() throws Exception { driver.get(baseUrl + "/Exchange/Mail/Contacts/List.aspx?selectedDomain=blahblahblah.com"); driver.findElement(By.linkText("Mr. Man")).click(); driver.findElement(By.linkText("Contact Information")).click(); new Select(driver.findElement(By.id("PhoneNumberType"))).selectByVisibleText("Mobile"); driver.findElement(By.id("MobilePhone")).sendKeys("999-999-9999"); new Select(driver.findElement(By.id("PhoneNumberType"))).selectByVisibleText("Fax"); driver.findElement(By.id("Fax")).sendKeys("999-999-9999"); driver.findElement(By.cssSelector("button.primary")).click(); } @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; } } private boolean isAlertPresent() { try { driver.switchTo().alert(); return true; } catch (NoAlertPresentException e) { return false; } } private String closeAlertAndGetItsText() { try { Alert alert = driver.switchTo().alert(); String alertText = alert.getText(); if (acceptNextAlert) { alert.accept(); } else { alert.dismiss(); } return alertText; } finally { acceptNextAlert = true; } } }
This gives me 4 errors (3 for annotations, which I could just delete, and one for fail in the tearDown() method. These are not the errors I'm worried about how to do this, is the code really executing?
Thanks!
java eclipse selenium
Man friday
source share