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)); } }

what’s the relationship between Selenium RC and WebDriver?

You should probably start your research here (though you may have already gone over this): http://seleniumhq.org/docs/03_webdriver.html I’ll assume you’re contrasting Selenium-RC to WebDriver, Selenium-IDE really isn’t in the same ballpark. Selenium uses JavaScript to automate web pages. This lets it interact very tightly with web content, and was one of the first automation tools to … Read more

Checking HTTP Status Code in Selenium

This might not be the best use of Selenium for this type of test. There is unnecessary need to load a browser when you could do and have a faster running test [Test] [ExpectedException(typeof(WebException), UserMessage = “The remote server returned an error: (404) Not Found”)] public void ShouldThrowA404() { HttpWebRequest task; //For Calling the page … Read more

Get PID of Browser launched by selenium

Using the Python API, it’s pretty simple: from selenium import webdriver browser = webdriver.Firefox() print browser.binary.process.pid # browser.binary.process is a Popen object… If you’re using Chrome, it’s a little more complex, you go via a chromedriver process: c = webdriver.Chrome() c.service.process # is a Popen instance for the chromedriver process import psutil p = psutil.Process(c.service.process.pid) … Read more

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