У меня проблема с настройкой тестов моего мобильного эмулятора.
По сути, у меня есть список мобильных устройств, которые я могу использовать для запуска тестов на селен на мобильных устройствах. Это пул устройств, который может использовать любой, кто заплатил за услугу, поэтому возможно, что в некоторых случаях эти устройства будут использоваться, и это создаст сеанс, а не созданное исключение. У меня проблема в том, что я используюпопытка / отлов, чтобы убедиться, что одно устройство недоступно, можно использовать другой набор возможностей устройства. У меня проблема в том, что иногда используются оба устройства, и тесты игнорируются. Это мой текущий код:
@BeforeClass
public void setup()throws Exception{
//Setup a mobile device on Kobiton, if this one is not available, the next one will be used
try {
this.driver = new RemoteWebDriver(config.kobitonServerUrl(), config.desiredCapabilitites_galaxyss7());
} catch (SessionNotCreatedException e) {
System.out.println("Secondary device being used");
this.driver = new RemoteWebDriver(config.kobitonServerUrl(), config.desiredCapabilitites_galaxys7());
}
}
Я связался, используя следующий код, но (! Done) не разрешен
boolean done = false;
while (!done) {
try {
...
done = true;
} catch (...) {
}
}
Я пробовал цикл, подобный этому, но ничего не происходит
@BeforeClass
public void setup()throws Exception{
boolean done = false;
while (!done)
try {
this.driver = new RemoteWebDriver (config.kobitonServerUrl(),
config.desiredCapabilitites_galaxyss7());
done = true;
} catch (SessionNotCreatedException e){
System.out.println("Secondary device being used");
this.driver = new RemoteWebDriver (config.kobitonServerUrl(),
config.desiredCapabilitites_galaxys7());
done = true;
}
}
Я также пытался
public class how_to_play_test {
private RemoteWebDriver driver = null;
@BeforeClass
public void setup()throws Exception{
int max_attempts = 10;
int attempts = 0;
boolean done = false;
while (attempts<max_attempts && !done) {
try {
this.driver = new RemoteWebDriver(config.kobitonServerUrl(), config.desiredCapabilitites_galaxyss7());
done = true;
} catch (SessionNotCreatedException e) {
System.out.println("Secondary device being used");
this.driver = new RemoteWebDriver(config.kobitonServerUrl(), config.desiredCapabilitites_galaxys7());
done = true;
}
attempts ++;
}
}
Полный тест
public class how_to_play_skip_test {
private RemoteWebDriver driver = null;
@BeforeClass
public void setup()throws Exception{
int max_attempts = 10;
int attempts = 0;
boolean done = true;
while ((max_attempts > attempts) && !done) {
try {
this.driver = new RemoteWebDriver(config.kobitonServerUrl(), config.desiredCapabilitites_galaxyss7());
done = true;
} catch (SessionNotCreatedException e) {
System.out.println("Secondary device being used");
this.driver = new RemoteWebDriver(config.kobitonServerUrl(), config.desiredCapabilitites_galaxys7());
done = true;
}
attempts ++;
}
}
@Test(priority=1)
public void how_to_play_skip_test_android() throws Exception {
driver.get("https://baseball-game-stage.com/howtoplay#howtoplay");
Thread.sleep(10000);
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement howto = driver.findElement(By.xpath("/html/body/aside/div/div[2]/div/div[1]/div[1]/div/div/div[1]/div/section/h2"));
wait.until(ExpectedConditions.visibilityOf(howto));
System.out.println("How to is displayed");
String how = driver.findElement(By.xpath("/html/body/aside/div/div[2]/div/div[1]/div[1]/div/div/div[1]/div/section/p")).getText();
//String how = how_to_play_text_element.getText();
System.out.println(how);
WebElement next = driver.findElement(By.cssSelector("[data-qa-action-button]"));
next.click();
driver.findElement(By.xpath("/html/body/aside/div/div[2]/div/div[1]/div[1]/div/div/div[2]/div/section/h2")).isDisplayed();
System.out.println("Game Picks is displayed");
String game_picks_text = driver.findElement(By.xpath("/html/body/aside/div/div[2]/div/div[1]/div[1]/div/div/div[2]/div/section/p")).getText();
System.out.println(game_picks_text);
Thread.sleep(3000);
next.click();
String submit_text = driver.findElement(By.xpath("/html/body/aside/div/div[2]/div/div[1]/div[1]/div/div/div[3]/div/section/p")).getText();
Assert.assertEquals("Complete your selections and submit your picks. Follow your progress on the big screen leaderboard.", submit_text);
System.out.println(submit_text);
WebElement finish = driver.findElement(By.cssSelector("[data-qa-action-button='finish']"));
finish.click();
Thread.sleep(3000);
}
@AfterClass
public void tear_down ()throws Exception {
driver.quit();
}
}