我正在测试不同浏览器(FireFox,Chrome,IE)上的应用程序。代码从Selenium IDE生成的代码
我测试硒IDE和我生成的代码java.on FireFox我更新每次更改生成的代码(id,cddSelector,Xpath ...),因为它不能很好地工作。此外,当我赞同Chrome上的相同测试,它不起作用,我必须第二次更改代码。
我有50到60个测试用例,使用这种方法很困难。
请问,你有任何想法使用相同的代码java的所有浏览器?
一个类的代码如下:
{
public class ConnexionMotDePasseErroneCommunFront {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
private String navigateur = "";
private String versionChrome="";
@Before
public void setUp() throws Exception {
baseUrl = Config.URLMULTISHIPING;
navigateur = Config.NAVIGATEUR;
switch (navigateur) {
case "firefox":
driver = new FirefoxDriver();
break;
case "chrome":
versionChrome=Config.VERSIONCHROMEDRIVER;
System.setProperty("webdriver.chrome.driver",new String("C:\\dev\\drivers\\ChromeDriver\\").concat(versionChrome).concat("\\chromedriver.exe"));
driver = new ChromeDriver();
break;
case "ie":
System.setProperty("webdriver.ie.driver",
"C:\\dev\\drivers\\IeDriver\\IEDriverServer.exe");
DesiredCapabilities sCaps = DesiredCapabilities.internetExplorer();
sCaps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
sCaps.setJavascriptEnabled(true);
driver = new InternetExplorerDriver(sCaps);
//driver = new InternetExplorerDriver();
case "opera":
driver = new OperaDriver();
break;
case "safari":
driver = new SafariDriver();
break;
default:
throw new RuntimeException("Browser type unsupported");
}
driver.manage().timeouts()
.implicitlyWait(Config.TIMEOUT, TimeUnit.SECONDS);
}
@Test
public void testConnexionMotDePasseErroneCommunFront() throws Exception {
driver.get(baseUrl + "/");
driver.findElement(By.id("mini-login")).click();
driver.findElement(By.id("mini-login")).clear();
driver.findElement(By.id("mini-login")).sendKeys("[email protected]");
driver.findElement(By.id("mini-password")).click();
driver.findElement(By.id("mini-password")).clear();
driver.findElement(By.id("mini-password")).sendKeys("123456");
driver.findElement(By.xpath("//button[@type='submit']")).click();
driver.findElement(
By.xpath("//a[@href='http://10.1.0.142:8081/customer/account/forgotpassword/']"))
.click();
driver.findElement(By.id("email_address")).sendKeys(
"[email protected]");
driver.findElement(By.xpath("//button[@type='submit']")).click();
driver.findElement(
By.xpath("//a[@href='http://10.1.0.142:8081/customer/account/login/']"))
.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;
}
}
}
}
,这是类配置的:
公共类配置{ 私有静态属性配置;
static {
if (config == null) {
config = new Properties();
try {
config.load(new FileInputStream("src/test/resources/config.properties"));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static final String NAVIGATEUR = config.getProperty("navigateur");
public static final String URLONEPAGE = config.getProperty("urlOnePage");
public static final String URLMULTISHIPING = config.getProperty("urlMultiShiping");
public static final String URLDEMO = config.getProperty("urlDEMO");
public static final Integer TIMEOUT = Integer.valueOf(config.getProperty("timeout"));
public static final String USER = config.getProperty("usernameBD");
public static final String PASSWORD=config.getProperty("passwordBD");
public static final String JDBC_DRIVER =config.getProperty("driver");
public static final String DB_URL=config.getProperty("cheminBd");
public static final String REQUEST=config.getProperty("requete");
public static final String EMAIL=config.getProperty("email");
public static final String PASS=config.getProperty("pass");
public static final String PASSNEW=config.getProperty("passNew");
public static final String ADRESSEEMAILOK=config.getProperty("adresseEmailOK");
public static final String PASSERR=config.getProperty("userPassErr");
public static final String EMAILDONNATEUR=config.getProperty("emailDonnateur");
public static final String EMAILADMIN=config.getProperty("emailAdmin");
public static final String PASSADMIN=config.getProperty("passAdmin");
public static final String NUMERO_CARTE_BANCAIRE=config.getProperty("numeroCarteBancaire");
public static final String TRIGRAMME=config.getProperty("triGramme");
public static final String PASSESPACEDONATEUR=config.getProperty("passEspaceDonateur");
public static final String STREET_1=config.getProperty("street_1");
public static final String STREET_1_NEW=config.getProperty("street_1_new");
public static final String CODEPOSTALE=config.getProperty("codePostale");
public static final String TEL=config.getProperty("tel");
public static final String VERSIONCHROMEDRIVER=config.getProperty("versionChromeDriver");
}
请,你能告诉我,如果IE浏览器的这个配置是正确的? :
System.setProperty(“webdriver.ie.driver”, “C:\ dev \ drivers \ IeDriver \ IEDriverServer.exe”);
DesiredCapabilities sCaps = DesiredCapabilities.internetExplorer();
sCaps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
sCaps.setJavascriptEnabled(true);
driver = new InternetExplorerDriver(sCaps);
由于提前
最好的问候,
嗨LittlePanda, – 2015-04-03 15:38:16
请问,你可以给我你的意见关于我的修改和加入的代码吗? – 2015-04-03 15:39:04