I can't believe I have to write a post about this, but my Selenium test is hanging in the Firefox browser. I don't have time to figure out if it's my Eclipse IDE causing the Java Runtime issue or my Maven (with I doubt although this is how I launch the test to run) or Selenium driver that I'm using in Maven.
But, I got tired of searching online for the same commands because I can't remember all these Linux commands. I just don't work in Linux Terminal enough to remember all this in addition to what I'm actually coding.
Here's the article I reference (and avoid rebooting my machine):
https://www.makeuseof.com/tag/6-different-ways-to-end-unresponsive-programs-in-linux/
Here's the command I typically use:
$ ps aux | grep firefox
$ kill <processID>
Go process hangups! (Really though, why are we still having these silly issues in 2018?)
Wednesday, October 24, 2018
Tuesday, October 23, 2018
Selenium Firefox - Test dynamic webelement with waits
Problem
The problem I am having today is that my test that was working is now having issues related to browser performance. I am testing for an element to display in two tabs. The first tab opens and the element is captured. Next, the second tab opens to the same exact page, but Selenium can't find the element to capture before closing the browser.I thought my implicit wait on the driver would suffice. It seemed to yesterday anyhow. So, now I am researching "waits".
https://www.seleniumhq.org/docs/04_webdriver_advanced.jsp
I didn't seen enough information on the main website for Java. So, I googled online for more information. Perhaps someone else has a cleaner solution? During my search, I noticed that there are two explicit waits: WebDriverWait and FluentWait. But, what is the difference?
FluentWait vs WebDriverWait
https://www.softwaretestingmaterial.com/webdriverwait-selenium-webdriverhttps://www.softwaretestingmaterial.com/selenium-fluentwait/
https://stackoverflow.com/questions/40753321/fluent-wait-vs-webdriver-wait
Essentially, the difference is FluentWait offers more handling of exceptions in case the Wait doesn't find the element, etc. This is my understanding so far. Thus, I'll continue with WebDriverWait which auto ignores exceptions (like NoSuchElementException).
This is all good to know, but useless without knowing the impact of the class ExpectedConditions. This class "ExpectedConditions" has some key methods that we need to know when looking for a specific element or element attribute or element value.
https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html
Well, there are a lot. Unfortunately, there aren't examples for each of these methods giving a descent explanation between the methods that appear similar.
Moving forward, this is an interesting, old article (posted in 2014). The author is first looking for the element and then looking for the text inside the element. Is this really necessary instead of simply looking for the text inside the element? Isn't there a wait on the element being completely rendered with text already? I don't know, but this would be to discover and understand.
http://www.software-testing-tutorials-automation.com/2014/01/webdriver-wait-for-text-to-be-present.html
Solution
Before digging into the details to understand, I discovered that this works. Here's my code which resolved my issue. Notice, this is a common method used by multiple tests.
public static Boolean isAgreementDisplayed(Webdriver driver, Integer waitSeconds) {
WebDriverWait wait = new WebDriverWait(drive, waitSeconds);
wait.until(ExpectedConditions.presenceOfElementLocated(By.className("modal-title")));
boolean modalTitleExists = wait.until(
ExpectedConditions.textToBePresentInElementLocated(By.className("modal-title"), "User Agreement"));
return modalTitleExists;
}
Now, if I remove the first "wait" call, will my code still work? Surprisingly, or maybe not surprisingly, it does work. So, now my code looks like this (although I know I can shorten it more) and my test waits for my dynamic webelement to display and check its text before completing assertion.
Cheers!
public static Boolean isAgreementDisplayed(Webdriver driver, Integer waitSeconds) {
WebDriverWait wait = new WebDriverWait(drive, waitSeconds);
boolean modalTitleExists = wait.until(
ExpectedConditions.textToBePresentInElementLocated(By.className("modal-title"), "User Agreement"));
return modalTitleExists;
}
Cheers!
Monday, October 22, 2018
Selenium Firefox - Test timeout error after waiting for timeout page
In this test, I want to verify the Timeout Error Page displays after a User has logged in successfully, but has not used the Application after 15 minutes.
Remember, my timeout is in units of seconds. So, adjusting my browser timeout to 15 * 60 seconds plus 30 more seconds to ensure my browser doesn't throw a timeout error before my application timeout. In case this calculation moved too fast because you haven't gotten your coffee yet, I need to wait for 15 minutes, these 15 minutes each have 60 seconds (i.e. 1 minute = 60 seconds, and I must test in seconds according to my function of units), and then I need to wait a few more seconds for my test script to capture the timeout text from the page display before my test browser times out (i.e. plus 30 seconds).
Here's my code.
@Test
public void testLoginTimeoutError() {
WebDriver firefoxDriver = new FirefoxDriver( new FirefoxProfile() );
firefoxDriver.manage().timeouts().implicitlyWait(60*15+30, TimeUnit.SECONDS);
Application.login(firefoxDriver, url, username, password);
WebElement myTimeOutElement = (new WebDriverWait(firefoxDriver, 60*15+5))
.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("blockquote h2")));
String timeOutText = myTimeOutElement.getText();
Assert.assertTrue("Error: The timeout error did not display as expected.",
timeOutText.equalsIgnoreCase("Your session has timed out"));
}
References
https://www.seleniumhq.org/docs/04_webdriver_advanced.jsp
Remember, my timeout is in units of seconds. So, adjusting my browser timeout to 15 * 60 seconds plus 30 more seconds to ensure my browser doesn't throw a timeout error before my application timeout. In case this calculation moved too fast because you haven't gotten your coffee yet, I need to wait for 15 minutes, these 15 minutes each have 60 seconds (i.e. 1 minute = 60 seconds, and I must test in seconds according to my function of units), and then I need to wait a few more seconds for my test script to capture the timeout text from the page display before my test browser times out (i.e. plus 30 seconds).
Here's my code.
@Test
public void testLoginTimeoutError() {
WebDriver firefoxDriver = new FirefoxDriver( new FirefoxProfile() );
firefoxDriver.manage().timeouts().implicitlyWait(60*15+30, TimeUnit.SECONDS);
Application.login(firefoxDriver, url, username, password);
WebElement myTimeOutElement = (new WebDriverWait(firefoxDriver, 60*15+5))
.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("blockquote h2")));
String timeOutText = myTimeOutElement.getText();
Assert.assertTrue("Error: The timeout error did not display as expected.",
timeOutText.equalsIgnoreCase("Your session has timed out"));
}
References
https://www.seleniumhq.org/docs/04_webdriver_advanced.jsp
Friday, October 19, 2018
Selenium Firefox (v2) - Test an Invalid User in Auth dialog on Application
I am trying to test how my web application handles an invalid user attempting to log in.
My Spring Security Application displays a Basic Authentication dialog (launched from the server side) before allowing the User to continue access into the web application (and render on client side). This dialog has only username and password fields.
I can't code lines that would enter the username and password into this authentication dialog. Thus, I followed a similar method like the solution given here:
http://www.tothenew.com/blog/easy-approach-to-handle-authentication-window-in-selenium-webdriver/
With a valid username and password, this code works and doesn't break my tests nor stops my test suite. However, with a an invalid username and password, this code does NOT work and breaks my testing. Specifically, the authentication dialog remains open (or displayed) in front of an open browser. I don't even know how to close this authentication dialog. How do I click 'Cancel' or 'OK' on this authentication dialog?
So, this is the problem I'm trying to solve.
I googled "selenium test invalid user in authentication dialog". From the results, I opened this StackOverflow article.
https://stackoverflow.com/questions/11522434/how-to-handle-login-pop-up-window-using-selenium-webdriver
From this StackOverflow article, there's a comment that led me to google "selenium firefox switch to alert". I see there's information on using Selenium to handle pop-up dialogs. Nice!
https://www.guru99.com/alert-popup-handling-selenium.html
https://stackoverflow.com/questions/30064528/java-selenium-firefox-driver-driver-switchto-alert-hangs-on-alert-dialo
So, I tried this and nothing from this article worked.
Further research, and I found these articles.
https://stackoverflow.com/questions/24304752/how-to-handle-authentication-popup-with-selenium-webdriver-using-java
This article has some comments which mention the use of Alert.authenticateUsing(), but seems that not all Drivers have this alert or method. At least, I didn't see it here:
https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/Alert.html
So, I googled "selenium firefox alert authenticateusing" and then read this article:
https://sqa.stackexchange.com/questions/25769/authentication-acting-as-alert-not-as-window
I tried this code, but this gave me the following error.
Error: NoAlertPresent No alert present (WARN...)
I realize this code didn't work because it's for Selenium 3 and I am using Selenium 2.53.
So, let's look into this article.
https://www.softwaretestingmaterial.com/handle-authentication-popup-window/
This article also did not help because I need to first resolve the issue with my driver not finding the alert dialog (i.e. authentication dialog).
Trying this article:
https://stackoverflow.com/questions/48823661/how-to-switch-to-window-authentication-popup-and-enter-credentials
Also, not helpful.
Trying this article:
https://sqa.stackexchange.com/questions/2277/using-selenium-webdriver-with-windows-authentication
This referenced article is great due to the author's explanation of using the Firefox add-on AutoAuth with steps to implement this solution.
http://www.codemiller.com/blog/2011/05/28/overcoming-auth-pop-ups/
Next, trying this article:
https://stackoverflow.com/questions/10395462/handling-browser-authentication-using-selenium
This also didn't provide a solution that I needed. Not for Selenium 2.
I guess I will just need to upgrade my Selenium version.
My Spring Security Application displays a Basic Authentication dialog (launched from the server side) before allowing the User to continue access into the web application (and render on client side). This dialog has only username and password fields.
I can't code lines that would enter the username and password into this authentication dialog. Thus, I followed a similar method like the solution given here:
http://www.tothenew.com/blog/easy-approach-to-handle-authentication-window-in-selenium-webdriver/
With a valid username and password, this code works and doesn't break my tests nor stops my test suite. However, with a an invalid username and password, this code does NOT work and breaks my testing. Specifically, the authentication dialog remains open (or displayed) in front of an open browser. I don't even know how to close this authentication dialog. How do I click 'Cancel' or 'OK' on this authentication dialog?
So, this is the problem I'm trying to solve.
I googled "selenium test invalid user in authentication dialog". From the results, I opened this StackOverflow article.
https://stackoverflow.com/questions/11522434/how-to-handle-login-pop-up-window-using-selenium-webdriver
From this StackOverflow article, there's a comment that led me to google "selenium firefox switch to alert". I see there's information on using Selenium to handle pop-up dialogs. Nice!
https://www.guru99.com/alert-popup-handling-selenium.html
https://stackoverflow.com/questions/30064528/java-selenium-firefox-driver-driver-switchto-alert-hangs-on-alert-dialo
So, I tried this and nothing from this article worked.
Further research, and I found these articles.
https://stackoverflow.com/questions/24304752/how-to-handle-authentication-popup-with-selenium-webdriver-using-java
This article has some comments which mention the use of Alert.authenticateUsing(), but seems that not all Drivers have this alert or method. At least, I didn't see it here:
https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/Alert.html
So, I googled "selenium firefox alert authenticateusing" and then read this article:
https://sqa.stackexchange.com/questions/25769/authentication-acting-as-alert-not-as-window
I tried this code, but this gave me the following error.
Error: NoAlertPresent No alert present (WARN...)
I realize this code didn't work because it's for Selenium 3 and I am using Selenium 2.53.
So, let's look into this article.
https://www.softwaretestingmaterial.com/handle-authentication-popup-window/
This article also did not help because I need to first resolve the issue with my driver not finding the alert dialog (i.e. authentication dialog).
Trying this article:
https://stackoverflow.com/questions/48823661/how-to-switch-to-window-authentication-popup-and-enter-credentials
Also, not helpful.
Trying this article:
https://sqa.stackexchange.com/questions/2277/using-selenium-webdriver-with-windows-authentication
This referenced article is great due to the author's explanation of using the Firefox add-on AutoAuth with steps to implement this solution.
http://www.codemiller.com/blog/2011/05/28/overcoming-auth-pop-ups/
Next, trying this article:
https://stackoverflow.com/questions/10395462/handling-browser-authentication-using-selenium
This also didn't provide a solution that I needed. Not for Selenium 2.
I guess I will just need to upgrade my Selenium version.
Types of Testing
Here's an article that I read recently and liked enough to share.
(In case this article is no longer available, the types covered are listed below).
https://www.softwaretestinghelp.com/types-of-software-testing/amp/
This author does an excellent job in covering most, if not all, different types of testing that exist.
Calling out "Mobile Testing" specifically is useful considering our current industry of technology and how there are more users on mobile technology (like smartphones and tablets) than the traditional technology (like desktops or even some laptops).
Either way, this goes to show that the extent of testing in the tech industry will always evolve and expand calling for better testing tools and methods. Good luck!
(In case this article is no longer available, the types covered are listed below).
https://www.softwaretestinghelp.com/types-of-software-testing/amp/
This author does an excellent job in covering most, if not all, different types of testing that exist.
Mobile Testing
One type of testing that I didn't see and expected to see is: Mobile Testing.Calling out "Mobile Testing" specifically is useful considering our current industry of technology and how there are more users on mobile technology (like smartphones and tablets) than the traditional technology (like desktops or even some laptops).
Additional Types of Testing (not in article)
A few other types of testing important to call out are:- API Testing - which is actually listed in the referencing article under Integration Testing
- IoT Testing - but this can be under Integration Testing
- Virtual Reality Testing
Either way, this goes to show that the extent of testing in the tech industry will always evolve and expand calling for better testing tools and methods. Good luck!
Different Types of Software Testing
- Alpha Testing
- Acceptance Testing
- Ad-hoc Testing
- Accessibility Testing
- Beta Testing
- Back-end Testing
- Browser Compatibility Testing
- Backward Compatibility Testing
- Black Box Testing
- Boundary Value Testing
- Branch Testing
- Comparison Testing
- Compatibility Testing
- Component Testing
- End-to-End Testing
- Equivalence Partitioning
- Example Testing
- Exploratory Testing
- Functional Testing
- Graphical User Interface (GUI) Testing
- Gorilla Testing
- Happy Path Testing
- Incremental Integration Testing
- Install/Uninstall Testing
- Integration Testing
- Load Testing
- Monkey Testing
- Mutation Testing
- Negative Testing
- Non-Functional Testing
- Performance Testing
- Recovery Testing
- Regression Testing
- Risk-Based Testing (RBT)
- Sanity Testing
- Security Testing
- Smoke Testing
- Static Testing
- Stress Testing
- System Testing
- Unit Testing
- Usability Testing
- Vulnerability Testing
- Volume Testing
- White Box Testing
Selenium Firefox - Test logging into two windows
I have a test case where I open first window and login. Next, I open a second window (not a tab) and I expect that I don't have to login. However, what I'm trying to understand is if the caching of the user credentials is in the browser session or not. I assume it is since I don't have to log back in (from a different window) when I'm already logged in another window that's still open.
I looked at this article, took some pointers and got the new tab to work.
https://www.testingexcellence.com/open-new-tab-browser-using-selenium-webdriver-java/
However, still working on the new window. Here's my code.
@Test
public void testNoLoginOnNewWindow() {
WebDriver driver2;
// Browser opened already (from @Before), login to application
JavelinApplication.login(driver1, url, username, password);
// Assert user's homepage displays
// Open new browser, navigate to application
driver2 = new FirefoxDriver(new FirefoxProfile());
driver2.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver2.navigate().to(url);
// Assert user's homepage displays without login credentials asked
driver2.quit();
}
This isn't quite working as expected yet. So, I read this article which didn't really help much:
https://stackoverflow.com/questions/17325629/how-to-open-a-new-window-on-a-browser-using-selenium-webdriver-for-python
But, it got me thinking. So, I re-read this article to leverage the code and open a new window from the existing open browser (similar to File -> New Window).
https://www.testingexcellence.com/open-new-tab-browser-using-selenium-webdriver-java/
Here's my code which actually worked as expected according to my test case.
@Test
public void testNoLoginOnNewWindow() {
// Browser opened already (from @Before), login to application
JavelinApplication.login(driver, url, username, password);
// Assert user's homepage displays
// Open new browser, navigate to application
driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL + "n");
ArrayList<String> windows = new ArrayList<String> (driver.getWindowHandles());
driver.switchTo().window(windows.get(1));
driver.navigate().to(url);
// Assert user's homepage displays without login credentials asked
}
Yay, hooray!
Here's my reasoning between the different code used.
On a Linux env, I already have one Firefox window (#1) opened with My Application homepage displayed. When I open a new Firefox window (#2) from the OS, I must enter the username/password credentials. I enter the username/password and see My Application homepage displayed. When I open a new Firefox window (#3) from one of the existing Firefox windows (#1 or #2), I am not asked for login credentials and see My Application homepage displayed.
On a Windows env, I already have one Firefox window (#1) opened with my Application homepage displayed. When I open a new Firefox window (#2) from the OS (using Windows Start Menu -> Run -> Type firefox), I see My Application homepage displayed in window and am not asked for user credentials.
My assumption is that the different behavior is due to the Operating System. I am not sure and would need to do further research and testing, but this explanation is sufficient for now since my goal with the test case was reached. Cheers!
I looked at this article, took some pointers and got the new tab to work.
https://www.testingexcellence.com/open-new-tab-browser-using-selenium-webdriver-java/
However, still working on the new window. Here's my code.
@Test
public void testNoLoginOnNewWindow() {
WebDriver driver2;
// Browser opened already (from @Before), login to application
JavelinApplication.login(driver1, url, username, password);
// Assert user's homepage displays
// Open new browser, navigate to application
driver2 = new FirefoxDriver(new FirefoxProfile());
driver2.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver2.navigate().to(url);
// Assert user's homepage displays without login credentials asked
driver2.quit();
}
This isn't quite working as expected yet. So, I read this article which didn't really help much:
https://stackoverflow.com/questions/17325629/how-to-open-a-new-window-on-a-browser-using-selenium-webdriver-for-python
But, it got me thinking. So, I re-read this article to leverage the code and open a new window from the existing open browser (similar to File -> New Window).
https://www.testingexcellence.com/open-new-tab-browser-using-selenium-webdriver-java/
Here's my code which actually worked as expected according to my test case.
@Test
public void testNoLoginOnNewWindow() {
// Browser opened already (from @Before), login to application
JavelinApplication.login(driver, url, username, password);
// Assert user's homepage displays
// Open new browser, navigate to application
driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL + "n");
ArrayList<String> windows = new ArrayList<String> (driver.getWindowHandles());
driver.switchTo().window(windows.get(1));
driver.navigate().to(url);
// Assert user's homepage displays without login credentials asked
}
Yay, hooray!
Here's my reasoning between the different code used.
On a Linux env, I already have one Firefox window (#1) opened with My Application homepage displayed. When I open a new Firefox window (#2) from the OS, I must enter the username/password credentials. I enter the username/password and see My Application homepage displayed. When I open a new Firefox window (#3) from one of the existing Firefox windows (#1 or #2), I am not asked for login credentials and see My Application homepage displayed.
On a Windows env, I already have one Firefox window (#1) opened with my Application homepage displayed. When I open a new Firefox window (#2) from the OS (using Windows Start Menu -> Run -> Type firefox), I see My Application homepage displayed in window and am not asked for user credentials.
My assumption is that the different behavior is due to the Operating System. I am not sure and would need to do further research and testing, but this explanation is sufficient for now since my goal with the test case was reached. Cheers!
Tuesday, October 16, 2018
Journey into SET: Part 2 (Resume stuff)
Here's my quick, informal resume points summarizing what I have been doing as a new Test Engineer Lead.
- Manage all SQA activities related to ensure product(s) quality including test plans, test designs, test implementation, test execution, and test maintenance. #sqa #sdlc
- Verify the system according to the system requirements and bring attention to management and development team(s) of any gaps between the system and its requirements documentation. #documentation #productvalidation
- Lead a team of two Test Engineers. #researchandtraining #peoplemanagement
- Provide information useful to management and development team(s) in assisting decision-making milestones for our clients. #statusreports #teamdiscussions
- Contribute to making our development team(s) and process(es) better by improving our test feedback loop with positive suggestions. #teamcommunication #jira
- Maximize the latest technologies in testing rapid application development (RAD) to ensure high-quality product delivery to customers. #testautomation #softwareengineerintest
Subscribe to:
Posts (Atom)