File tree Expand file tree Collapse file tree
tests/mytests/src/test/java/tests Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -197,7 +197,7 @@ advanced:
197197 link : " https://www.browserstack.com/guide/take-screenshots-in-selenium"
198198
199199 headless_execution : # 4 pts | once
200- done : false
200+ done : true
201201 description : " Run tests in headless mode (browser without visible UI)"
202202 link : " https://www.selenium.dev/documentation/webdriver/browsers/chrome/"
203203
Original file line number Diff line number Diff line change @@ -24,17 +24,20 @@ public void loginTest() {
2424
2525 loginPage = login (loginPage );
2626
27- sharedMainPage =loginPage .clickLogin ();
27+ sharedMainPage = loginPage .clickLogin ();
2828 Assert .assertTrue (sharedMainPage .getBodyText ().contains ("Hi, Elte!" ));
2929 Assert .assertFalse (sharedMainPage .getBodyText ().contains ("Log in" ));
3030 Assert .assertEquals ("Dashboard | ELTESelTest" , sharedMainPage .getTitle ());
31+
32+ System .out .println ("Login test completed." );
3133 }
3234
3335 @ Test (dependsOnMethods = { "loginTest" })
3436 public void logoutTest () {
3537 sharedMainPage .toggleUserMenu ();
3638 sharedMainPage .clickLogout ();
3739 Assert .assertTrue (sharedMainPage .getBodyText ().contains ("Log in" ));
40+ System .out .println ("Logout test completed." );
3841 }
3942
4043
Original file line number Diff line number Diff line change 1+ package tests ;
2+
3+ import java .net .MalformedURLException ;
4+
5+ import org .testng .annotations .*;
6+ import org .testng .*;
7+
8+ import pages .LoginPage ;
9+ import pages .MainPage ;
10+
11+ public class HeadlessModeTest extends TestBase {
12+
13+ @ BeforeClass
14+ public void Setup () throws MalformedURLException
15+ {
16+ options .addArguments ("--headless=new" );
17+ options .addArguments ("--window-size=1920,1080" );
18+
19+ options .addArguments ("--no-sandbox" );
20+ options .addArguments ("--disable-dev-shm-usage" );
21+ options .addArguments ("--disable-gpu" );
22+
23+ options .addArguments ("--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" );
24+ options .addArguments ("--lang=en-US" );
25+ before ();
26+ }
27+
28+ @ Test
29+ public void headlessModeTest () {
30+ LoginPage loginPage = null ;
31+
32+ loginPage = login (loginPage );
33+
34+ MainPage mainPage = loginPage .clickLogin ();
35+ Assert .assertTrue (mainPage .getBodyText ().contains ("Hi, Elte!" ));
36+ Assert .assertFalse (mainPage .getBodyText ().contains ("Log in" ));
37+ Assert .assertEquals ("Dashboard | ELTESelTest" , mainPage .getTitle ());
38+
39+ System .out .println ("Headless mode test completed." );
40+ }
41+
42+ @ AfterClass
43+ public void close () {
44+ after ();
45+ }
46+
47+ }
Original file line number Diff line number Diff line change 1515public class TestBase {
1616
1717 protected WebDriver driver ;
18+ protected ChromeOptions options = new ChromeOptions ();
1819
1920 protected void before () throws MalformedURLException {
2021 final Map <String , Object > chromePrefs = new HashMap <>();
2122 chromePrefs .put ("profile.password_manager_leak_detection" , false );
2223
2324 ChromeOptions options = new ChromeOptions ();
24- options .setExperimentalOption ("prefs" , chromePrefs );
25+ options .setExperimentalOption ("prefs" , chromePrefs );
2526
2627 this .driver = new RemoteWebDriver (new URL (ConfigReader .get ("selenium_url" )), options );
2728 this .driver .manage ().window ().maximize ();
Original file line number Diff line number Diff line change @@ -43,6 +43,8 @@ public void courseCreation() {
4343 CoursePage coursePage = courseCreatorPage .submitCreateCourse ();
4444 Assert .assertTrue (coursePage .getBodyText ().contains ("Selenium Testing Course " + randomNum ));
4545
46+ System .out .println ("Course creation test completed." );
47+
4648 //Assert.assertTrue(courseCreatorPage.getBodyText().contains("Selenium Testing Course"));
4749 }
4850
@@ -66,9 +68,16 @@ public void cookieHandling() {
6668 driver .manage ().deleteCookieNamed ("MoodleSessionelteseleniumtesting" );
6769 driver .navigate ().refresh ();
6870
71+ try {
72+ Thread .sleep (2000 );
73+ } catch (InterruptedException e ) {
74+ e .printStackTrace ();
75+ }
76+
6977 Assert .assertFalse (mainPage .getBodyText ().contains ("Hi, Elte!" ));
7078 Assert .assertTrue (mainPage .getBodyText ().contains ("Log in" ));
7179
80+ System .out .println ("Cookie handling test completed." );
7281 }
7382
7483
You can’t perform that action at this time.
0 commit comments