Best SeLion code snippet using com.paypal.selion.reports.runtime.SeLionReporter
Source:SeLionReporter.java
...31/**32 * A TestNG compatible message logger. Use this class to log messages to the report output and associate them with a33 * {@link Test}, {@link WebTest} and/or {@link MobileTest}34 */35public final class SeLionReporter {36 private static final SimpleLogger logger = SeLionLogger.getLogger();37 private volatile static List<LogAction> actionList = new ArrayList<LogAction>();38 private static String output;39 private static DataSaver saver;40 private final String baseFileName = UUID.randomUUID().toString();41 private BaseLog currentLog;42 private String getBaseFileName() {43 return baseFileName;44 }45 private BaseLog getCurrentLog() {46 return currentLog;47 }48 private void setCurrentLog(BaseLog currentLog) {49 this.currentLog = currentLog;50 }51 /**52 * Sets string path to the output53 * 54 * @param rootFolder55 * path to the output folder56 */57 public static void setTestNGOutputFolder(String rootFolder) {58 output = rootFolder;59 }60 /**61 * <ol>62 * <li>Provides saver with path to output information.63 * <li>Initializes saver.<br>64 * <li>Creates if missing output directories.<br>65 * </ol>66 */67 public static void init() {68 logger.entering();69 saver = new SaverFileSystem(output);70 saver.init();71 logger.exiting();72 }73 /**74 * Creates an instance of {@link BaseLog}. Calls any {@link LogAction}s which are hooked in.75 * 76 * @param saveSrc77 * Save the current page source <code>true/false</code>. Requires an active {@link Grid} session.78 * @return A {@link BaseLog} subclass that represents the actual log that was generated.79 */80 protected BaseLog createLog(boolean saveSrc) {81 String href = null;82 /**83 * Changed html file extension to txt84 */85 if (!(saver instanceof SaverFileSystem)) { // NOSONAR86 throw new RuntimeException("Internal error. SeLionReporter expects an instance of SaverFileSystem."); // NOSONAR87 }88 if (saveSrc) {89 PageContents source = new PageContents(Grid.driver().getPageSource(), getBaseFileName());90 saver.saveSources(source);91 href = "sources" + File.separator + getBaseFileName() + ".source.txt";92 getCurrentLog().setHref(href);93 }94 for (LogAction eachAction : actionList) {95 eachAction.perform();96 }97 return getCurrentLog();98 }99 /**100 * Generate a log message and send it to the TestNG {@link Reporter}101 * 102 * @param takeScreenshot103 * Take a screenshot <code>true/false</code>. Requires an active {@link Grid} session.104 * @param saveSrc105 * Save the current page source <code>true/false</code>. Requires an active {@link Grid} session.106 */107 protected void generateLog(boolean takeScreenshot, boolean saveSrc) {108 logger.entering(new Object[] { takeScreenshot, saveSrc });109 try {110 BaseLog log = createLog(saveSrc);111 String screenshotPath = null;112 log.setScreen(null);113 if (takeScreenshot) {114 // screenshot115 PageContents screen = new PageContents(Gatherer.takeScreenshot(Grid.driver()), getBaseFileName());116 screenshotPath = saver.saveScreenshot(screen);117 log.setScreen(screenshotPath);118 }119 // creating a string from all the info for the report to deserialize120 Reporter.log(log.toString());121 } catch (Exception e) {122 logger.log(Level.SEVERE, "error in the logging feature of SeLion " + e.getMessage(), e);123 }124 logger.exiting();125 }126 /**127 * @param action128 * A {@link LogAction} object that represents the custom log action to be invoked when129 * {@link SeLionReporter#log(String, boolean, boolean)} gets called.130 * 131 */132 public static void addLogAction(LogAction action) {133 if (!actionList.contains(action)) {134 actionList.add(action);135 }136 }137 /**138 * Generates log entry with message provided139 * 140 * @param message141 * Entry description142 * @param takeScreenshot143 * Take a screenshot <code>true/false</code>. Requires an active {@link Grid} session.144 */145 public static void log(String message, boolean takeScreenshot) {146 log(message, takeScreenshot, false);147 }148 /**149 * Generates log entry with message provided150 * 151 * @param message152 * Entry description153 * @param takeScreenshot154 * Take a screenshot <code>true/false</code>. Requires an active {@link Grid} session.155 * @param saveSrc156 * Save the current page source <code>true/false</code>. Requires an active {@link Grid} session.157 */158 public static void log(String message, boolean takeScreenshot, boolean saveSrc) {159 SeLionReporter reporter = new SeLionReporter();160 BaseLog currentLog = new BaseLog();161 currentLog.setMsg(message);162 currentLog.setLocation(Gatherer.saveGetLocation(Grid.driver()));163 reporter.setCurrentLog(currentLog);164 reporter.generateLog(takeScreenshot, saveSrc);165 logger.exiting();166 }167}...
Source:AppiumSauceCloudTest.java
...21import org.testng.annotations.Test;22import com.paypal.selion.annotations.MobileTest;23import com.paypal.selion.platform.grid.Grid;24import com.paypal.selion.platform.utilities.WebDriverWaitUtils;25import com.paypal.selion.reports.runtime.SeLionReporter;26/**27 * This class has test cases that demonstrates how to use SeLion for running tests against mobile apps using sauce cloud.28 */29public class AppiumSauceCloudTest {30 /**31 * This test demonstrates how to use SeLion for running tests against a Native ANDROID app in sauce cloud.32 * This selendroid-test-app-0.15.0.apk must be uploaded to sauce temporary storage before running this test case.33 */34 @Test35 @MobileTest(appPath = "sauce-storage:selendroid-test-app-0.15.0.apk", device = "android:4.3",36 deviceType = "Android Emulator", additionalCapabilities = { "appiumVersion:1.4.13" })37 public void testWithNativeAndroidApp() throws Exception {38 RemoteWebDriver driver = Grid.driver();39 WebDriverWaitUtils.waitUntilElementIsVisible("io.selendroid.testapp:id/my_text_field");40 WebElement textField = driver.findElement(By.id("io.selendroid.testapp:id/my_text_field"));41 assertEquals("true", textField.getAttribute("enabled"));42 textField.sendKeys("Appium Android Native Test");43 assertEquals("Appium Android Native Test", textField.getText());44 }45 46 /**47 * This test demonstrates how to use SeLion for running tests against a Native IOS app in sauce cloud. 48 * InternationalMountains.app.zip must be uploaded to sauce temporary storage before running this test case.49 */50 @Test51 @MobileTest(appPath = "sauce-storage:InternationalMountains.app.zip", device = "iphone:8.1",52 deviceType = "iPhone Simulator", additionalCapabilities = { "appiumVersion:1.4.13" })53 public void testWithNativeIOSApp() throws InterruptedException {54 SeLionReporter.log("My Screenshot 1", true);55 List<WebElement> cells = Grid.driver().findElements(By.className("UIATableCell"));56 assertEquals(9, cells.size());57 // get the 1st mountain58 WebElement first = cells.get(0);59 first.click();60 Thread.sleep(10 * 1000);61 SeLionReporter.log("My Screenshot 2", true);62 }63}...
Source:IOSNativeAppDemoTest.java
...20import org.testng.annotations.Test;21import static org.testng.Assert.assertEquals;22import com.paypal.selion.annotations.MobileTest;23import com.paypal.selion.platform.grid.Grid;24import com.paypal.selion.reports.runtime.SeLionReporter;25/**26 * This test class demonstrates how to use SeLion for running tests against a Native iOS app.27 * 28 */29public class IOSNativeAppDemoTest {30 /**31 * This test demonstrates how to use SeLion for running tests against a Native IOS app using appium.32 * This test case needs an local IOS simulator spawned. 33 */34 @MobileTest(appName = "InternationalMountains")35 @Test36 public void testMethod() throws InterruptedException {37 //Log a screenshot to the report and label it "My Screenshot 1"38 SeLionReporter.log("My Screenshot 1", true);39 //To gain access to the IOSRemoteWebDriver, we use the thread safe helper method Grid.driver() 40 //which provides an instance of IOSRemoteWebDriver for the current Test method. 41 List<WebElement> cells = Grid.driver().findElements(By.className("UIATableCell"));42 assertEquals(9, cells.size());43 // get the 1st mountain44 WebElement first = cells.get(0);45 first.click();46 Thread.sleep(10 * 1000);47 //Log a screenshot to the report and label it "My Screenshot 2"48 SeLionReporter.log("My Screenshot 2", true);49 // access the content50 By selector = By.xpath("//UIAStaticText[contains(@name,'climbed')]");51 WebElement text = Grid.driver().findElement(selector);52 Reporter.log(text.getAttribute("name"),true);53 }54}...
SeLionReporter
Using AI Code Generation
1import org.testng.annotations.Test;2import com.paypal.selion.reports.runtime.SeLionReporter;3import com.paypal.selion.reports.runtime.SeLionReporter;4import com.paypal.selion.reports.runtime.SeLionReporter;5import com.paypal.selion.reports.runtime.SeLionReporter;6public class SeLionReporterTest {7 public void testSeLionReporter() {8 SeLionReporter.log("This is a sample message", true);9 SeLionReporter.log("This is a sample message", false);10 SeLionReporter.log("This is a sample message", true, false);11 SeLionReporter.log("This is a sample message", false, false);12 }13}
SeLionReporter
Using AI Code Generation
1package com.paypal.selion.reports.runtime;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.support.FindBy;5import org.openqa.selenium.support.PageFactory;6import org.openqa.selenium.support.ui.ExpectedConditions;7import org.openqa.selenium.support.ui.WebDriverWait;8import org.testng.Assert;9import org.testng.annotations.Test;10public class SeLionReporterTest {11 WebDriver driver;12 @FindBy(id = "email")13 WebElement email;14 @FindBy(id = "pass")15 WebElement password;16 @FindBy(id = "loginbutton")17 WebElement login;18 @FindBy(id = "userNavigationLabel")19 WebElement userNavigationLabel;20 WebElement logout;21 public SeLionReporterTest(WebDriver driver) {22 this.driver = driver;23 PageFactory.initElements(driver, this);24 }25 public void login(String email, String password) {26 this.email.sendKeys(email);27 this.password.sendKeys(password);28 login.click();29 }30 public void logout() {31 userNavigationLabel.click();32 logout.click();33 }34 public void testLoginLogout() {35 login("
SeLionReporter
Using AI Code Generation
1import com.paypal.selion.reports.runtime.SeLionReporter;2import com.paypal.selion.reports.runtime.SeLionReporter;3import com.paypal.selion.reports.runtime.SeLionReporter;4public class 3 {5public static void main(String[] args) {6SeLionReporter.log("This is a log message", true);7SeLionReporter.log("This is a log message", false);8SeLionReporter.log("This is a log message", true);9SeLionReporter.log("This is a log message", false);10SeLionReporter.log("This is a log message", true);11SeLionReporter.log("This is a log message", false);12SeLionReporter.log("This is a log message", true);13SeLionReporter.log("This is a log message", false);14SeLionReporter.log("This is a log message", true);15SeLionReporter.log("This is a log message", false);16SeLionReporter.log("This is a log message", true);17SeLionReporter.log("This is a log message", false);18}19}
SeLionReporter
Using AI Code Generation
1package com.paypal.selion.reports.runtime;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.firefox.FirefoxDriver;4import org.testng.annotations.AfterMethod;5import org.testng.annotations.BeforeMethod;6import org.testng.annotations.Test;7import com.paypal.selion.annotations.WebTest;8import com.paypal.selion.platform.grid.Grid;9import com.paypal.selion.platform.grid.browsercapabilities.DefaultCapabilitiesBuilder;10import com.paypal.selion.platform.utilities.WebDriverWaitUtils;11public class SeLionReporterTest {12 private WebDriver driver;13 public void beforeMethod() {14 }15 public void testMethod1() {16 WebDriverWaitUtils.waitUntilElementIsPresent("name=q");17 }18 public void testMethod2() {19 WebDriverWaitUtils.waitUntilElementIsPresent("name=p");20 }21 public void afterMethod() {22 SeLionReporter reporter = new SeLionReporter();23 reporter.generateReport();24 driver.quit();25 }26}27package com.paypal.selion.reports.runtime;28import org.openqa.selenium.WebDriver;29import org.openqa.selenium.firefox.FirefoxDriver;30import org.testng.annotations.AfterMethod;31import org.testng.annotations.BeforeMethod;32import org.testng.annotations.Test;33import com.paypal.selion.annotations.WebTest;34import com.paypal.selion.platform.grid.Grid;35import com.paypal.selion.platform.grid.browsercapabilities.DefaultCapabilitiesBuilder;36import com.paypal.selion.platform.utilities.WebDriverWaitUtils;37public class SeLionReporterTest {38 private WebDriver driver;39 public void beforeMethod() {40 }41 public void testMethod1() {42 WebDriverWaitUtils.waitUntilElementIsPresent("name=q");43 }44 public void testMethod2() {
SeLionReporter
Using AI Code Generation
1import com.paypal.selion.reports.runtime.SeLionReporter;2import org.testng.annotations.Test;3public class TestClass {4public void testMethod(){5SeLionReporter.log("This is a test method",true);6}7}
SeLionReporter
Using AI Code Generation
1import com.paypal.selion.reports.runtime.SeLionReporter;2import com.paypal.selion.reports.runtime.SeLionReporter.*;3public class 3 {4public static void main(String[] args) throws Exception {5SeLionReporter.setReporter(new ExtentHtmlReporter("C:\\Users\\Desktop\\report.html"));6SeLionReporter.startTest("Test1", "Description");7SeLionReporter.log("info", "info logged");8SeLionReporter.log("warning", "warning logged");9SeLionReporter.log("error", "error logged");10SeLionReporter.log("fatal", "fatal logged");11SeLionReporter.log("pass", "pass logged");12SeLionReporter.log("fail", "fail logged");13SeLionReporter.log("skip", "skip logged");14SeLionReporter.log("debug", "debu
SeLionReporter
Using AI Code Generation
1package com.paypal.selion.reports.runtime;2import org.testng.annotations.Test;3public class TestSeLionReporter {4public void testSeLionReporter() {5SeLionReporter.log("Test", true);6SeLionReporter.log("Test", true, true);7SeLionReporter.log("Test", true, true, false);8SeLionReporter.log("Test", true, true, false, false);9SeLionReporter.log("Test", true, true, false, false, false);10SeLionReporter.log("Test", true, true, false, false, false, false);11SeLionReporter.log("Test", true, true, false, false, false, false, false);12SeLionReporter.log("Test", true, true, false, false, false, false, false, false);13SeLionReporter.log("Test", true, true, false, false, false, false, false, false, false);14SeLionReporter.log("Test", true, true, false, false, false, false, false, false, false, false);15SeLionReporter.log("Test", true, true, false, false, false, false, false, false, false, false, false);16SeLionReporter.log("Test", true, true, false, false, false, false, false, false, false, false, false, false);17SeLionReporter.log("Test", true, true, false, false, false, false, false, false, false, false, false, false, false);18SeLionReporter.log("Test", true, true, false, false, false, false, false, false, false, false, false, false, false, false);19SeLionReporter.log("Test", true, true, false, false, false, false, false, false, false, false, false, false, false, false, false);20SeLionReporter.log("Test", true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false);21SeLionReporter.log("Test", true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false);22SeLionReporter.log("Test", true, true, false, false
SeLionReporter
Using AI Code Generation
1package com.paypal.selion.testcases;2import org.testng.annotations.Test;3import com.paypal.selion.reports.runtime.SeLionReporter;4public class CustomReport {5 public void testCustomReport() {6 SeLionReporter.log("This is a custom report for a test case", true);
SeLionReporter
Using AI Code Generation
1import com.paypal.selion.reports.runtime.SeLionReporter;2public class TestClass extends SeLionReporter {3 public void testMethod() {4 SeLionReporter.log("custom step", true);5 }6}7import com.paypal.selion.reports.runtime.SeLionReporter;8public class TestClass extends SeLionReporter {9 public void testMethod() {10 SeLionReporter.log("custom step", true);11 }12}13import com.paypal.selion.reports.runtime.SeLionReporter;14public class TestClass extends SeLionReporter {15 public void testMethod() {16 SeLionReporter.log("custom step", true);17 }18}19import com.paypal.selion.reports.runtime.SeLionReporter;20public class TestClass extends SeLionReporter {21 public void testMethod() {22 SeLionReporter.log("custom step", true);23 }24}25import com.paypal.selion.reports.runtime.SeLionReporter;26public class TestClass extends SeLionReporter {27 public void testMethod() {28 SeLionReporter.log("custom step", true);29 }30}31import com.paypal.selion.reports.runtime.SeLionReporter;32public class TestClass extends SeLionReporter {33 public void testMethod() {34 SeLionReporter.log("custom step", true);
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!