Open MrRahulR opened 7 years ago
If you're receiving that error than the jQuery Growl library isn't loading correctly during your test's browser session.
Can you provide your test code?
I've copied and pasted the code provided on your project the differences are I used TestNG instead of JUnit there & Chrome instead of Firefox. Below is the code.
package com.ratedr.growl;
import java.io.File;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class Growl {
WebDriver driver;
JavascriptExecutor js;
@BeforeClass
public void setUp() throws Exception {
File file = new File(System.getProperty("user.dir") + "//chromedriver.exe");
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
driver = new ChromeDriver();
js = (JavascriptExecutor) driver;
}
@AfterClass
public void tearDown() throws Exception {
driver.quit();
}
@Test
public void growlTest() throws InterruptedException {
driver.get("http://the-internet.herokuapp.com/");
// Check for jQuery on the page, add it if need be
js.executeScript("if (!window.jQuery) {"
+ "var jquery = document.createElement('script'); jquery.type = 'text/javascript';"
+ "jquery.src = 'https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js';"
+ "document.getElementsByTagName('head')[0].appendChild(jquery);" + "}");
// Use jQuery to add jquery-growl to the page
js.executeScript("$.getScript('http://the-internet.herokuapp.com/js/vendor/jquery.growl.js')");
// Use jQuery to add jquery-growl styles to the page
js.executeScript("$('head').append('<link rel=\"stylesheet\" "
+ "href=\"http://the-internet.herokuapp.com/css/jquery.growl.css\" " + "type=\"text/css\" />');");
// jquery-growl w/ no frills
js.executeScript("$.growl({ title: 'GET', message: '/' });");
// jquery-growl w/ colorized output
js.executeScript("$.growl.error({ title: 'ERROR', message: 'your error message goes here' });");
js.executeScript("$.growl.notice({ title: 'Notice', message: 'your notice message goes here' });");
js.executeScript("$.growl.warning({ title: 'Warning!', message: 'your warning message goes here' });");
Thread.sleep(5000);
}
}
Thanks! I'll take a look.
Hi @tourdedave , Anything you found in it?
Environment - OS: Windows 8 Selenium Version: 3.4.0 Browser: Google Chrome Browser Version: Chrome 61.0 (64-bit)
Expected Behavior - The script should work properly and the user can see the growl notification in the browser.
Actual Behavior - Error display for the jQuery functions while running the script with Selenium & Java.
Stack trace -