| 42 | import com.microsoft.playwright.Video; |
| 43 | |
| 44 | public class ProjectHooks extends PlaywrightWrapper { |
| 45 | |
| 46 | // This is for the email that you may need to use within test automation |
| 47 | protected static final ThreadLocal<String> email = new ThreadLocal<String>(); |
| 48 | |
| 49 | public static Map<String,String> newEmails; |
| 50 | public static String videoFolderName = "videos/"; |
| 51 | public static String tracesFolderName = "videos/"; |
| 52 | |
| 53 | |
| 54 | /** |
| 55 | * Will be invoked before once for every test suite execution and create video folder and the reporting |
| 56 | * @author TestLeaf |
| 57 | */ |
| 58 | @BeforeSuite |
| 59 | public void initSuite() { |
| 60 | newEmails = new HashMap<String, String>(); |
| 61 | videoFolderName = createFolder("videos"); |
| 62 | tracesFolderName = createFolder("traces"); |
| 63 | |
| 64 | startReport(); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * This method will take snapshot in base64 format |
| 69 | * @author TestLeaf |
| 70 | */ |
| 71 | @Override |
| 72 | public String takeSnap(){ |
| 73 | return new String(Base64.getEncoder().encode(getPage().screenshot())); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Will be invoked before once for every test case execution and |
| 78 | * a) will launch the browser based on config |
| 79 | * b) create reporting structure |
| 80 | * c) store login state (if configured) |
| 81 | * d) create context, page |
| 82 | * e) set default time out based on config |
| 83 | * f) maximize and load the given URL |
| 84 | * @author TestLeaf |
| 85 | */ |
| 86 | @BeforeMethod |
| 87 | public void init() { |
| 88 | try { |
| 89 | // Launch the browser (based on configuration) in head(less) mode (based on configuration) |
| 90 | setDriver(ConfigurationManager.configuration().browser(), ConfigurationManager.configuration().headless()); |
| 91 | |
| 92 | // Set the extent report node for the test |
| 93 | setNode(); |
| 94 | |
| 95 | // Default Settings |
| 96 | NewContextOptions newContext = new Browser.NewContextOptions() |
| 97 | .setIgnoreHTTPSErrors(true) |
| 98 | .setRecordVideoDir(Paths.get(folderName)); |
| 99 | |
| 100 | // Auto Login if enabled |
| 101 | if(ConfigurationManager.configuration().autoLogin()) { |
nothing calls this directly
no outgoing calls
no test coverage detected