Czas na zadanie z ciasteczek. Będziesz mieć okazję poćwiczyć to, co przerobiliśmy wspólnie w kilku ostatnich filmach.
Na początku filmu tłumaczę polecenie, a następnie rozwiązanie. Będzie moment żeby zatrzymać film na czas wykonania zadania – dam znać w filmie kiedy.
Hej Ela,
udało mi się wykonać to zadanie, jednak przy każdym uruchamianiu całego testu ciągle zmienia się liczba ciastek, w różnych miejscach z 'asercjami'. Nie widzę, też żeby dany test odpalał się w trybie incognito, o którym mówiłaś. Czy wiesz co może być przyczyną ?
Halko! Zacznę od końca - to nie jest tak naprawd [...] CAŁOŚĆ KOMENTARZA WIDOCZNA DLA SUBSKRYBENTÓW.
Cześć i Czołem !
Słuchaj spędziłem dwie godziny nad jedną linijką kodu,
system bez przerwy wyrzuca mi
Null Pointer Exception
Próbowałem już i iść w składnie i w waity, bez przerwy ten sam komunikat :-/
Chodzi mi o ostatni Assert 🙂
Ratunku !
@Test
public void ela3()
{
driver.get("http://motorlublin.com.pl/");
Set raz = driver.manage().getCookies();
Assert.assertEquals(4, driver.manage().getCookies().size());
Cookie newCookie = new Cookie("test_cookie","test_value",".motorlublin.com.pl","/",
new GregorianCalendar(2019,11,11).getTime(),true,true);
driver.manage().addCookie(newCookie);
try { Thread.sleep(5000);}
catch (InterruptedException e) { e.printStackTrace(); }
Assert.assertEquals("Number of the cookie is not correct",newCookie.getName(),
driver.manage().getCookieNamed("test_cookie").getName());
}
Cześć! Pierwsza sprawa - nie wiem czy używasz s [...] CAŁOŚĆ KOMENTARZA WIDOCZNA DLA SUBSKRYBENTÓW.
Cześć, nie wiem o co chodzi, ale nie mogę w debuggerze zobaczyć ilości cookies ;/ test nie przechodzi. Nie mam pojęcia czemu.
Wyskakuje mi taki komunikat:
java.lang.NullPointerException
at DriverMethods.ExcerciseTwo.cookieExercise(ExcerciseTwo.java:34)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:134)
at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:597)
at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:173)
at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:816)
at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:146)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1507)
at org.testng.TestRunner.privateRun(TestRunner.java:766)
at org.testng.TestRunner.run(TestRunner.java:587)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:384)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:378)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:337)
at org.testng.SuiteRunner.run(SuiteRunner.java:286)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1187)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1109)
at org.testng.TestNG.runSuites(TestNG.java:1039)
at org.testng.TestNG.run(TestNG.java:1007)
at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:110)
java.lang.NullPointerException
at DriverMethods.ExcerciseTwo.CloseAndQuit(ExcerciseTwo.java:27)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:134)
at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:63)
at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:348)
at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:302)
at org.testng.TestRunner.invokeTestConfigurations(TestRunner.java:619)
at org.testng.TestRunner.afterRun(TestRunner.java:849)
at org.testng.TestRunner.run(TestRunner.java:590)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:384)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:378)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:337)
at org.testng.SuiteRunner.run(SuiteRunner.java:286)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1187)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1109)
at org.testng.TestNG.runSuites(TestNG.java:1039)
at org.testng.TestNG.run(TestNG.java:1007)
at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:110)
===============================================
Default Suite
Total tests run: 1, Passes: 0, Failures: 1, Skips: 0
Configuration Failures: 1, Skips: 0
===============================================
Process finished with exit code 0
Halko! A porównałaś ten kod z moim? Podpowiem C [...] CAŁOŚĆ KOMENTARZA WIDOCZNA DLA SUBSKRYBENTÓW.
i jeszcze jedno pytanie: czemu w IntelliJ "znika" czasem opcja puszczenia testu albo debuggera??
Nie do końca wiem co masz na myśli pisząc, że [...] CAŁOŚĆ KOMENTARZA WIDOCZNA DLA SUBSKRYBENTÓW.
np jak klikam prawym myszy to nie mam opcji "run test" itp. zielonej strzałki też nie mam obok @Test. Okazało się, że coś namieszałam - po poprawkach strzałka wróciła na miejsce
Całe szczęście, że wróciło 😀 [...] CAŁOŚĆ KOMENTARZA WIDOCZNA DLA SUBSKRYBENTÓW.
Hej, ciasteczka chyba nie za bardzo mnie lubią. Po wykonaniu prostego testu z pobraniem ciasteczek ze strony, test mi failuje i pokazuje, że aktualna liczba ciastek na stronie wikipedii to 3, po wejściu na wikipedie w tryb incognito widzę 4 ciasteczka. Czy to podobna sytuacja co przy Amazonie, ze ciastka zyja wlasnym zyciem?
Komunikat:
org.opentest4j.AssertionFailedError:
Expected :4
Actual :3
screen: https://zapodaj.net/d6bd129385058.png.html
Kod:
Tak sobie myślę, że w tym wypadku w momencie po [...] CAŁOŚĆ KOMENTARZA WIDOCZNA DLA SUBSKRYBENTÓW.
O zapomniałam o nim! dziękuje bardzo:)
Czy dla punktów 4 i 5 asercja może wyglądać w ten sposób?
Assertions.assertNull(driver.manage().getCookieNamed("test_cookie"), "Cookie doesn't exist");
ps. Jak się wstawia sformatowany kod w komentarzach? 🙂
Halko! A sprawdziłeś co się stanie jak coś tak [...] CAŁOŚĆ KOMENTARZA WIDOCZNA DLA SUBSKRYBENTÓW.
Sprawdzałem co się stanie i z test jest na pass. Jak sama wspominałaś, napisanie testu na pass wcale nie jest trudne. Dlatego postanowiłem zapytać 🙂
Jeśli dobrze rozumiem to Assertions.assertNull sprawdza czy obiekt jest null, więc w tym przypadku sprawdzam czy cookie o name "test_cookie" istnieje. Jeśli nie istnieje to wszystko w porządku.
A widzisz, miałam pewne podejrzenie, że ta metod [...] CAŁOŚĆ KOMENTARZA WIDOCZNA DLA SUBSKRYBENTÓW.
Po zakomentowaniu linijki z usuwaniem ciastka w konsoli pojawia się coś takiego:
Wygląda, że jest dobrze.
ps. Faktycznie jest ściąga. Nie zwróciłem uwagi 🙂
Dokładnie, wygląda ok 😉 [...] CAŁOŚĆ KOMENTARZA WIDOCZNA DLA SUBSKRYBENTÓW.