Capturing JavaScript error in Selenium

I’m doing this to capture JavaScript errors: [TestCleanup] public void TestCleanup() { var errorStrings = new List<string> { “SyntaxError”, “EvalError”, “ReferenceError”, “RangeError”, “TypeError”, “URIError” }; var jsErrors = Driver.Manage().Logs.GetLog(LogType.Browser).Where(x => errorStrings.Any(e => x.Message.Contains(e))); if (jsErrors.Any()) { Assert.Fail(“JavaScript error(s):” + Environment.NewLine + jsErrors.Aggregate(“”, (s, entry) => s + entry.Message + Environment.NewLine)); } }

How to continue execution when Assertion is failed

I suggest you to use soft assertions, which are provided in TestNg natively package automation.tests; import org.testng.asserts.Assertion; import org.testng.asserts.SoftAssert; public class MyTest { private Assertion hardAssert = new Assertion(); private SoftAssert softAssert = new SoftAssert(); } @Test public void testForSoftAssertionFailure() { softAssert.assertTrue(false); softAssert.assertEquals(1, 2); softAssert.assertAll(); } Source: http://rameshbaskar.wordpress.com/2013/09/11/soft-assertions-using-testng/

Page scroll up or down in Selenium WebDriver (Selenium 2) using java

Scenario/Test steps: 1. Open a browser and navigate to TestURL 2. Scroll down some pixel and scroll up For Scroll down: WebDriver driver = new FirefoxDriver(); JavascriptExecutor jse = (JavascriptExecutor)driver; jse.executeScript(“window.scrollBy(0,250)”); OR, you can do as follows: jse.executeScript(“scroll(0, 250);”); For Scroll up: jse.executeScript(“window.scrollBy(0,-250)”); OR, jse.executeScript(“scroll(0, -250);”); Scroll to the bottom of the page: Scenario/Test steps: … Read more

tech