1
Javaはかなり基本的なもので、私はSeleniumの新機能です。何らかの理由で私のコードで、私はコンソールで「アサート」の結果を見ることができますが、他の部分ではそうすることはできません。私はアサーションの前後でコンソールにメッセージを記録しましたが(どちらもどちらも表示されますが)、アサーションの結果は表示されません。Eclipse - コンソールでアサーションの結果を見ることができません
package automationFramework;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import static org.junit.Assert.*;
public class Weather {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.gecko.driver", "//home//aaronh//Documents//Drivers//geckodriver");
// System.setProperty("webdriver.gecko.driver",
// "//home//aaron//JARs//geckodriver-v0.14.0-linux64//geckodriver");
WebDriver driver = new FirefoxDriver();
// launch browser and go to the website
String url = "https://www.bbc.com/weather";
driver.get(url);
driver.manage().window().maximize();
// search weather information for Bristol
WebElement location = driver.findElement(By.name("search"));
location.clear();
location.sendKeys("Bristol, Bristol");
// click search button
WebElement search = driver.findElement(By.name("submitBtn"));
search.click();
// this assertion fails because it checks the title before the search and IS LOGGED TO THE CONSOLE
// for
// Bristol weather has finished
// String bristol = driver.getTitle();
// assertEquals("BBC Weather - Bristol", bristol);
System.out.println("before wait");
WebDriverWait wait = new WebDriverWait(driver, 5);
if (wait.until(ExpectedConditions.titleContains("BBC Weather - Bristol"))) {
String bristol = driver.getTitle();
System.out.println("before assert " + bristol);
// this does not log to the console
assertEquals("BBC Weather - Bristol", bristol);
System.out.println("after assert");
}
driver.close();
System.out.println("Test script executed successfully.");
System.exit(0);
}
}
誰かが、アサーションが1つの場所に出力され、他の場所に出力されない理由を教えてください。 getTitleは意味がありません。なぜなら、タイトルが私たちが主張しているものでない限り、これらのコードを取得できないからです。ちょっと試してみました。
ありがとうございました。
アサート<>()ではありません。メソッドは例外をスローするように設定され、system.out.print()のような操作を使用してコンソールに直接ログしませんか?とにかく、assertEuals()の時点でアサーションが失敗した場合は、私が信じるすべての "assert after"文を見てはいけませんか?とにかくmain()にあるものを@ Test-methodに入れてみましょう。 :) – vegaasen
ああ、アサートが失敗した場合、コンソールに出力されます(私は「BBC - 天気 - Bristoll」と比較するように変更しました)。 – Rookie