I'm trying to test our website with selenium via Jenkins so that everyday every feature gets tested.
The problem is that Jenkins fails because he is trying to get the chromedriver with my local path but there is no local path.
The error message:
[ERROR] main(at.s2gplus.selenium.TestPromoteToAdmin) Time elapsed:
0.006 s <<< FAILURE! java.lang.IllegalStateException: The driver executable does not exist:
/opt/jenkins/workspace/buzzApi/C:/Users/mario/AppData/Local/Google/Chrome/Application/chromedriver.exe
at
at.s2gplus.selenium.TestPromoteToAdmin.main(TestPromoteToAdmin.java:36)
The code:
public class TestPromoteToAdmin {
WebDriver driver = new ChromeDriver();
#Test
public void main() {
driver.get("https://192.168.1.45:8080/");
WebDriverWait wait = new WebDriverWait(driver, 90);
driver.manage().window().maximize();
driver.findElement(By.id("details-button")).click();
driver.findElement(By.id("proceed-link")).click();
driver.findElement(By.id("home-open-sign-in")).click();
driver.findElement(By.id("login-username")).sendKeys("tester");
driver.findElement(By.id("login-password")).sendKeys("wurst01");
driver.findElement(By.id("login-action")).click();
wait.until(ExpectedConditions.elementToBeClickable(By.id("left-menu-room-title-add-action"))).click();
driver.findElement(By.id("create-room-name-input")).sendKeys("Selenium Admin test");
driver.findElement(By.id("create-room-description-input")).sendKeys("Selenium Test");
driver.findElement(By.id("create-room-save")).click();
JavascriptExecutor js = (JavascriptExecutor) driver;
WebElement roomToClick = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[contains(text(), 'Selenium Admin test')]")));
js.executeScript("arguments[0].scrollIntoView();", roomToClick);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
wait.until(ExpectedConditions.elementToBeClickable(roomToClick)).click();
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[contains(#id, 'left-roomlist-settingsicon')]"))).click();
WebElement addMemberBtn = wait.until(ExpectedConditions.elementToBeClickable(By.id("room-settings-add-user")));
addMemberBtn.click();
WebElement checkBox = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("label[for='990bd6a8-62af-48c5-89a5-33019483c91f'")));//("cb732433-eae9-434b-96da-b4d5a499208c"));
checkBox.click();
WebElement addBtn = driver.findElement(By.id("room-settings-add-button"));
addBtn.click();
WebElement saveUserBtn = driver.findElement(By.id("room-settings-save"));
saveUserBtn.click();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[contains(#id, 'left-roomlist-settingsicon')]"))).click();
wait.until(ExpectedConditions.elementToBeClickable(By.id("general-menu-list-item-settings"))).click();
wait.until(ExpectedConditions.elementToBeClickable(By.id("room-settings-context-change-role-to-moderator"))).click();
wait.until(ExpectedConditions.elementToBeClickable(By.id("general-menu-list-item-settings"))).click();
wait.until(ExpectedConditions.elementToBeClickable(By.id("room-settings-context-change-role-to-admin"))).click();
driver.findElement(By.id("room-settings-save")).click();
driver.findElement(By.id("top-logout")).click();
driver.findElement(By.id("home-open-sign-in")).click();
driver.findElement(By.id("login-username")).sendKeys("tester01");
driver.findElement(By.id("login-password")).sendKeys("wurst02");
driver.findElement(By.id("login-action")).click();
roomToClick = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[contains(text(), 'Selenium Admin test')]")));
js.executeScript("arguments[0].scrollIntoView();", roomToClick);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
wait.until(ExpectedConditions.elementToBeClickable(roomToClick)).click();
WebElement roomAdmin = driver.findElement(By.xpath("//span[contains(text(), 'Selenium Admin test')]"));
String room = roomAdmin.getText();
assertTrue(room, true);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[contains(#id, 'left-roomlist-settingsicon')]"))).click();
wait.until(ExpectedConditions.elementToBeClickable(By.id("meeting-settings-open-close-room-modal"))).click();
wait.until(ExpectedConditions.elementToBeClickable(By.id("meeting-settings-close-room-confirm"))).click();
}
#BeforeTest
public void beforeTest() {
ChromeOptions options = new ChromeOptions();
options.setHeadless(true);
options.setAcceptInsecureCerts(true);
driver = new ChromeDriver(options);
}
#AfterTest
public void afterTest() {
driver.quit();
}
}
line 36 is above driver.get("https://192.168.1.45:8080/"); but I have deleted it a long time ago
Install Selenium Grid Plugin in the Jenkins, use below code for node setup. Update the versions of selenium server standalone jar and browser versions in the below code.
java -jar selenium-server-standalone-x.xx.x.jar -
Dwebdriver.chrome.driver="C:\yourpath\chromedriver.exe" -role node -hub
http://localhost:4444/grid/register -browser "browserName=internet
explorer,version=xx,platform=WINDOWS" -browser
"browserName=chrome,version=xx,platform=WINDOWS"
Please update below line of code for starting
WebDriver driver = null;
#Test
public void main() {
System.setProperty("webdriver.chrome.driver","E:\\drivers\\ChromeDrivers\\85\\chromedriver.exe");
driver = new ChromeDriver();
driver.get("https://192.168.1.45:8080/");
WebDriverWait wait = new WebDriverWait(driver, 90);
driver.manage().window().maximize(); ```
Related
Trying to locate Radio Button inside iFrame but getting error as No Such Element found.
Tried switching to iFrame but still getting the same error. Not sure what am I missing. Tried couple of methods but did not get through. Not sure if my Xpath is wrong or way I use id to locate element is wrong. [Verified my Xpath in Developer tools but still getting the same error of No suh Element found]
Thank you in advance.
public class Sap_Demo {
WebDriver driver;
JavascriptExecutor jse;
public static void main(String[] args)
{
Sap_Demo demoObj = new Sap_Demo();
demoObj.invokeBrowser();
demoObj.initializeSAPFiory();
demoObj.forecastMD61();
}
public void invokeBrowser()
{
System.setProperty("webdriver.chrome.driver", "U:\\Research Paper\\Selenium\\Drivers\\Chrome\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().deleteAllCookies();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
}
public void initializeSAPFiory()
{
try
{
Thread.sleep(1200);
driver.get("https://dijon.cob.csuchico.edu:8042/erp");
driver.findElement(By.id("USERNAME_FIELD-inner")).sendKeys("H4");
Thread.sleep(1200);
driver.findElement(By.id("PASSWORD_FIELD-inner")).sendKeys("Onsjhjsa1087");
Thread.sleep(1200);
driver.findElement(By.id("CLIENT_FIELD-inner")).clear();
Thread.sleep(1200);
driver.findElement(By.id("CLIENT_FIELD-inner")).sendKeys("485");
Thread.sleep(1200);
driver.findElement(By.xpath("//span[#class='sapMBtnContent sapMLabelBold sapUiSraDisplayBeforeLogin']")).click();
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void forecastMD61()
{
try {
driver.findElement(By.id("erpsim-tcode-btn-img")).click();
Thread.sleep(1200);
driver.findElement(By.id("TCode-input-inner")).sendKeys("MD61");
Thread.sleep(1200);
driver.findElement(By.id("TCode-launchBtn-content")).click();
Thread.sleep(1200);
driver.switchTo().defaultContent();
WebElement iframe = driver.findElement(By.id("ITSFRAME1"));
driver.switchTo().frame(iframe);
/*driver.switchTo().frame(driver.findElement(By.xpath("//span[#id='M0:46:::4:2-imgSymb']")));
driver.findElement(By.xpath("//span[#id='M0:46:::4:2-imgSymb']")).sendKeys("ABC");*/
//driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
//Thread.sleep(1600);
/*driver.switchTo().frame("ITSFRAME1");
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("ITSFRAME1"));*/
/*WebElement E1 = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("M0:46:::4:2-imgStd")));
WebElement E1 = driver.findElement(By.xpath("//span[#id='M0:46:::4:2-imgSymb']"));
E1.click();*/
//driver.findElement(By.id("M0:46:::4:2-imgStd")).click();
//driver.findElement(By.xpath("//span[#id='M0:46:::4:2-imgStd']")).click();
//Thread.sleep(1200);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
Your first xpath for the element and the id for the iframe are correct, but as the window is getting opened in a new tab, you need to switch the driver to the new tab.
So, instead of using driver.switchTo().defaultContent();
You need to use:
ArrayList<String> tabs = new ArrayList<String> (driver.getWindowHandles());
driver.switchTo().window(tabs.get(1));
And if you want to switch to the original tab, you need to use:
driver.switchTo().window(tabs.get(0));
I've installed the Gecko driver because i was getting this error : "java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property;"
But after applying the code still i'm getting error for Gecko driver.
Below is my complete code. please let me know what I'm missing.
public class Pawan {
public static WebDriver driver;
public static void main(String[] args){
System.setProperty("webdriver.firefox.marionette","C:\\Users\\Lalit-pc\\Desktop\\geckodriver-v0.21.0-win64\\geckodriver.exe");
driver = new FirefoxDriver();
}
#Test
public void test() {
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("https://www.google.com/");
driver.findElement(By.linkText("Find a Physician")).click();
driver.findElement(By.id("searchZip")).sendKeys("32806");
driver.findElement(By.linkText("Mile Radius")).click();
try{
Thread.sleep(6000);
}catch (InterruptedException ie1) {
ie1.printStackTrace();
}
driver.findElement(By.linkText("20")).click();
driver.findElement(By.linkText("Specialty")).click();
try{
Thread.sleep(6000);
}catch (InterruptedException ie1) {
ie1.printStackTrace();
}
driver.findElement(By.linkText("Anesthesiology")).click();
driver.findElement(By.cssSelector("input[type='submit'][value='Search Now']")).click();
String str= driver.findElement(By.xpath(".//*[#id='finderListView']/div[3]/div[1]/div/div[1]/p")).getText();
if("Anesthesiology".equals(str))
System.out.println("Physician Search Successful");
else
System.out.println("Physician Search NOT Successful");
driver.findElement(By.linkText("Browse Locations")).click();
try{
Thread.sleep(6000);
}catch (InterruptedException ie1) {
ie1.printStackTrace();
}
driver.findElement(By.xpath(".//*[#id='sidebarMenu']/div[1]/form/div/input")).sendKeys("32806");
driver.findElement(By.xpath(".//*[#id='sidebarMenu']/div[1]/form/input")).click();
try{
Thread.sleep(6000);
}catch (InterruptedException ie1) {
ie1.printStackTrace();
}
driver.findElement(By.xpath(".//*[#id='sidebarMenu']/div[2]/section/div/ul/li[1]/a")).click();
try{
Thread.sleep(6000);
}catch (InterruptedException ie1) {
ie1.printStackTrace();
}
WebElement divElement = driver.findElement(By.xpath(".//*[#id='overflow-autoScroll']/li[1]/ul/li/a/div[2]/span[3]"));
String stri = divElement.getText();
if(stri.contains("32806"))
System.out.println("Location Search successful");
else
System.out.println("Location Search not successful");
driver.findElement(By.xpath("html/body/header/div[1]/div[2]/a[3]")).click();
driver.findElement(By.linkText("Health Topics")).click();
try{
Thread.sleep(6000);
}catch (InterruptedException ie1) {
ie1.printStackTrace();
}
driver.findElement(By.linkText("Diabetes")).click();
WebElement divElementtwo = driver.findElement(By.xpath("html/body/div[4]/div/div[1]/div[1]/h2"));
String strn = divElementtwo.getText();
if(strn.contains("Diabetes"))
System.out.println("Blog Search successful");
else
System.out.println("Blog Search not successful");
}
}
To verify gecko driver is compatible with your current firefox & selenium version, do the following:
Keep downloaded gecko driver at System32 if you are on Windows OS & /usr/local/bin if you are on Mac OSX
Run the Selenium Standalone server by this command: java -jar selenium-server-standalone-3.13.0.jar
Open this url in Firefox browser: http://localhost:4444/wd/hub
Create Session and Select Firefox browser
If browser starts then there is no issue with the compatibility of geckodriver with Firefox & Selenium version.
small setup change requied: (latest firefox browser)
public class Pawan {
public static WebDriver driver;
#BeforeClass
public static setup() {
System.setProperty("webdriver.gecko.driver","C:\\Users\\Lalit-pc\\Desktop\\geckodriver-v0.21.0-win64\\geckodriver.exe");
driver = new FirefoxDriver();
}
// Urs test here
JUnit uses a different main entry point than the public static void main(String[] args) method you've defined there, so if you execute the tests, System#setProperty won't be executed.
To add the system property once for all tests in the class, you need to define a #BeforeClass method:
public class Pawan {
public static WebDriver driver;
#BeforeClass
static void init() {
System.setProperty("webdriver.firefox.marionette","C:\\Users\\Lalit-pc\\Desktop\\geckodriver-v0.21.0-win64\\geckodriver.exe");
}
//test cases here...
}
Now, for development purposes, I recommend setting this variable as a constant accessible by your PATH environment variable (OS dependent) rather than setting it as a system property.
You can also define geckodriver in #Test if you do not want #BeforeClass annotation :
#Test
public void test() {
System.setProperty("webdriver.firefox.marionette","C:\\Users\\Lalit-pc\\Desktop\\geckodriver-v0.21.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("https://www.google.com/");
This will also work:)
I write my test on my local Windows, and I create webdriver like this:
#BeforeMethod
#Parameters("browser")
public void setUp(String browser) throws Exception {
if (browser.equalsIgnoreCase("chrome")) {
System.out.println("Chrome test starting ...");
System.setProperty("webdriver.chrome.driver", "src/test/resources/drivers/chromedriver_win.exe");
webDriver = new ChromeDriver();
}
else {
throw new Exception("Browser is not supported");
}
For the setProperty, I use a hard path to Chrome Driver, but I would like change the path to relative by checking the OS to use appropriate driver for Windows and Mac. Can someone give me a hint. Thanks
By using config property file you can get both browser type and chrome driver location.
you can create one folder in your work space with the name Drivers and paste your chrome driver
Below is config.properties file
browserType=Chrome
ChromeDriver = Drivers/chromedriver.exe
Below is the code to run chrome driver on different operating systems
String os = System.getProperty("os.name");
public String currentBrowser;
if(CONFIG.getProperty("browserType").contains(","))
{
data=currentBrowser;
}
if (os.contains("Windows"))
{
else if (data.equals("Chrome")) {
APP_LOGS.debug("Chrome Browser Opening Method Start");
DesiredCapabilities capability = DesiredCapabilities.chrome();
// To Accept SSL certificate
capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
System.setProperty("webdriver.chrome.driver",
CONFIG.getProperty("ChromeDriver"));
Thread.sleep(10000);
driver = new ChromeDriver();
driver.manage().window().maximize();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
long
implicitWaitTime=Long.parseLong(CONFIG.getProperty("implicitwait"));
driver.manage().timeouts().implicitlyWait(implicitWaitTime,
TimeUnit.SECONDS);
driver.manage().window().maximize();
}
return os;
}
Why are you putting chromedriver in src? Your jar will be needing that folders while running.
Source Code and the Binary files should not be put together in production environment.
Create a libs folder and put all types of chromedrivers in it. With slight change in name.
chromedriver_mac
chromedriver_win
chromedriver_linux
Code
#BeforeMethod
#Parameters("browser")
public void setUp(String browser) throws Exception {
if (browser.equalsIgnoreCase("chrome")) {
System.out.println("Chrome test starting ...");
System.setProperty("webdriver.chrome.driver", getChromeDriverPath());
webDriver = new ChromeDriver();
}
else {
throw new Exception("Browser is not supported");
}
}
public static String getChromeDriverPath() {
String OS = System.getProperty("os.name");
if (OS.contains("Window")) {
return "libs/chromedriver_win"
} else if (OS.contains("Mac")) {
return "libs/chromedriver_mac"
} else {
return "libs/chromedriver_linux"
}
}
The below code should work,
if(type.equalsIgnoreCase("CHROME"))
{
log.info("Executing Operating System = "+System.getProperty("os.name").toLowerCase());
String osname =System.getProperty("os.name");
if(osname.toLowerCase().contains("windows")) System.setProperty("webdriver.chrome.driver","src/test/resources/chromedriver.exe" );
else if(osname.toLowerCase().contains("linux"))
{
String filepathtoset = System.getProperty("user.dir")+"/src/test/resources/chromedriver";
System.setProperty("webdriver.chrome.driver",filepathtoset );
}
else System.setProperty("webdriver.chrome.driver","src/test/resources/chromedrivermac");
I am facing issues with Selenium when navigating from one page to another.
Below is the code. If I click on following element a jQuery image will open until the next page gets loaded. But it's not navigating to next page itself. The image keeps on rotating and window will close that. Why?
I am getting a NoSuchElementFoundException
Chrome Version : 58.0.3029.110
driver.findElement(By.name("continue")).click();
#Test
public void executeLoginApp() throws InterruptedException {
driver.navigate()
.to("url with login application");
WebElement userName = driver.findElement(By.id("uname"));
WebElement pwd = driver.findElement(By.id("passwd"));
userName.sendKeys("test");
pwd.sendKeys("test");
Thread.sleep(2000);
javaScriptExecutor.executeScript("window.scrollTo(0, document.body.scrollHeight)");
Thread.sleep(2000);
//driver.findElement(By.xpath("//input[#name='continue']")).click();
//Thread.sleep(1000);
//driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
driver.findElement(By.name("continue")).click();
//signOn.click();
callYourInformation();
}
private void callYourInformation() {
/*try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
WebDriverWait wait = new WebDriverWait(driver, 10);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
String previousURL = driver.getCurrentUrl();
ExpectedCondition e = new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return (d.getCurrentUrl() != previousURL);
}};
wait.until(e);}*/
// currentURL = driver.getCurrentUrl();
if (driver.getCurrentUrl().contains("yourinfo")) {
// testing yourinfo page
WebElement emailAddress = driver.findElement(By.id("emailAddress"));
emailAddress.clear();
emailAddress.sendKeys("selenium#wwwmail.com");
WebElement addressLine1 = driver.findElement(By.id("addressLine1"));
addressLine1.clear();
addressLine1.sendKeys("New york");
WebElement grossAnnualIncome = driver.findElement(By.id("grossAnnualIncome"));
grossAnnualIncome.sendKeys(String.valueOf(6000));
WebElement submit = driver.findElement(By.id("submitApplication"));
submit.click();
driver.findElement(By.id("Continue")).click();
}
else{
do other logic.
}
I tried all the ways but no luck. Commented lines are my tries but none of them redirects to that page.
I have used 3 drivers firefox, chrome and IE for automated testing.
static WebDriver driver ;
public static void main(String args[]) {
try {
driver = new FirefoxDriver();
runTest(driver, "FireFox");
//Chrome
System.setProperty("webdriver.chrome.driver","E:/selinium_drivers/chromedriver.exe");
driver = new ChromeDriver();
runTest(driver, "Chrome");
//IE
System.setProperty("webdriver.ie.driver","E:/selinium_drivers/IEDriverServer.exe");
driver = new InternetExplorerDriver();
runTest(driver, "IE");
}
The problem is the second driver is starting before the first driver complete it's process. How can i stop second driver till the first driver finish it work.
public static void runTest(WebDriver driver, String browserName) {
try {
testLogin(driver);
testSignupC(driver);
testSignUpCLogin(driver);
driver.close();
} catch(Exception ex) {
//log stack trace
//Alter(test failed in browser name)
}
}
You didn't mention your WebDriver version; my comments are based on API 2.45.
First, you should call driver.quit() instead of close():
/**
* Close the current window, quitting the browser if it's the last window currently open.
*/
void close();
/**
* Quits this driver, closing every associated window.
*/
void quit();
Second, you should secure the driver shutdown in a finally block:
try {
testLogin(driver);
testSignupC(driver);
testSignUpCLogin(driver);
} catch(Exception ex) {
//log stack trace
//Alter(test failed in browser name)
} finally {
driver.quit();
}
Additionally, I would surround quit() with a try/catch on WebDriverException and set driver to null in order to prevent its reuse since the driver initialization (startClient(), startSession()...) is done in the constructor:
} finally {
try {
driver.quit();
catch (WebDriverException e) {
// log if useful else NO OP
}
driver = null;
}