In creating the Test Framework using Selenium for testing a specific web application, I am sort of shocked that the authors of Selenium would allow a WebElement to be "clicked" but not keep track whether this WebElement "isClicked" or even "isClickable".
https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/WebElement.html#click--
So, anyhow, learned the hard way and had to really pay attention to reading the large paragraph in the API's method definition when it should the method should hanlde such cases or the Object should allow for handling such cases.
But, there's my issue too - why am I not contributing to this open source library set (tool)?
I need to get my game up and contribute, not complain.
I got around my problem and solved using the:
driver.navigate.refresh()
Well, at least I now know. :D
Showing posts with label test automation. Show all posts
Showing posts with label test automation. Show all posts
Friday, January 11, 2019
Monday, December 31, 2018
Review: Exploratory vs Manual Testing
@fwmoyer states the difference between Exploratory Testing and Manual Testing is a mindset. And I agree with him. Here's a quick article on explaining why.
https://www.softwaretestinghelp.com/exploratory-testing-vs-scripted-testing/
Overall, context is always valuable when driving something purposeful. In order to reach quality results (i.e. results that matter and add value), context is required especially to help to create productive roadmaps whether designing, developing, and/or testing.
https://www.softwaretestinghelp.com/exploratory-testing-vs-scripted-testing/
Overall, context is always valuable when driving something purposeful. In order to reach quality results (i.e. results that matter and add value), context is required especially to help to create productive roadmaps whether designing, developing, and/or testing.
Thursday, December 27, 2018
Reference on Test Tools of 2018
As we come to close the year 2018, here are a few articles on the test tools shaping the industry (tech and all others) and that will continue to add value into 2019.
Notice that one of the rising stars is TestIM.io. Keep an eye on this company, its tool(s), and its service(s).
Notice that one of the rising stars is TestIM.io. Keep an eye on this company, its tool(s), and its service(s).
Software Testing Help - Top 20 automation testing tools (Dec 2018)
Actually, this is the only article I found online that was recent (aka relevant) and didn't seem to have a bias toward any tools (i.e. promoting commercial over open source, etc).
More importantly, let's keep an eye on the AI automated tools. Just like robots are replacing people in factories, AI will replace the mundane programming jobs. Therefore, humans will need to learn how to establish more roles in the R&D industry (which ironically was almost wiped out by corporations in the early 2000s due to foolish business cuts).
Tuesday, December 4, 2018
JayWay - JsonPath
Today I read a couple articles from TestProject and found this new library quite interesting (when a Maven project uses this library).
https://github.com/json-path/JsonPath
This library helps to format the structure of a JSON file/response.
https://github.com/json-path/JsonPath
This library helps to format the structure of a JSON file/response.
Thursday, November 8, 2018
Journey into SET: Creating Test Framework in Selenium
So, I'm still on my journey back into becoming a Software Test Engineer (expert) and geesh, there's a lot to catch up on.
Today, I'm looking into creating a Test Framework with Selenium.
I googled on "selenium creating test framework" to see results and learn.
Why?
First, let's answer why I'm researching this topic. I am able to create test scripts using Selenium and my test are passing. However, as I'm creating a test suite and adding more tests, I find myself using the same code for multiple @Test. I'd like to reduce the code, use wrappers around Selenium's code, and condense my @Test to be specific on focusing on the test case. This also helps with test script maintenance. For instance, if I need all of my test scripts to navigate to their corresponding page (add form -> New Form, edit form -> Form, etc). Then, I realize I need the User to click OK to a dialog just implemented before displaying any form. I don't want to have to check this code for each test script in each @Test.
YouTube(s) I watched.
https://www.youtube.com/watch?v=DO8KVe00kcU
Article(s) I read.
https://simpleprogrammer.com/creating-automated-testing-framework-selenium/
Not very useful, unless going to author's course.
https://www.testingexcellence.com/develop-test-automation-framework-scratch/
I like the breakdown on this author's GitHub and see it's practical use. So, I decided to implement this same framework.
Pattern Insights
Since I'm using the PageObject pattern, this was very helpful to know.
https://github.com/SeleniumHQ/selenium/wiki/PageFactory
Today, I'm looking into creating a Test Framework with Selenium.
I googled on "selenium creating test framework" to see results and learn.
Why?
First, let's answer why I'm researching this topic. I am able to create test scripts using Selenium and my test are passing. However, as I'm creating a test suite and adding more tests, I find myself using the same code for multiple @Test. I'd like to reduce the code, use wrappers around Selenium's code, and condense my @Test to be specific on focusing on the test case. This also helps with test script maintenance. For instance, if I need all of my test scripts to navigate to their corresponding page (add form -> New Form, edit form -> Form, etc). Then, I realize I need the User to click OK to a dialog just implemented before displaying any form. I don't want to have to check this code for each test script in each @Test.
YouTube(s) I watched.
https://www.youtube.com/watch?v=DO8KVe00kcU
Article(s) I read.
https://simpleprogrammer.com/creating-automated-testing-framework-selenium/
Not very useful, unless going to author's course.
https://www.testingexcellence.com/develop-test-automation-framework-scratch/
I like the breakdown on this author's GitHub and see it's practical use. So, I decided to implement this same framework.
Pattern Insights
Since I'm using the PageObject pattern, this was very helpful to know.
https://github.com/SeleniumHQ/selenium/wiki/PageFactory
Tuesday, November 6, 2018
Software Testing Article: TestIM Era of AI
Today's article that catches my attention and has good links in it is by TestIM's webinar.
Friday, November 2, 2018
Selenium Firefox - use common functions like getButton(buttonText)
Selenium Experts recommend that those who use the tool and implement it to test their applications (like me) should create wrappers specific to their application for the general code snippets frequently used. This is a long way of saying that we need to create common functions used by many Test methods.
For example, I need a common function that clicks a button given the button text. I don't want to have to keep writing this long code snippet:
(new WebDriverWait(driver, waitSeconds)).until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(CssFormButtonBegin+buttonText+CssFormButtonEnd))).click();
Instead, I would like to use a common function like:
public void clickButton(String buttonText) {
getButton(String buttonText);
}
public void getButton(String buttonText) {
// code that gets the WebElement of button type in CssSelector
// cssDoesNotWork = "button:contains('buttonText')"
// cssWorks = "form.className button#buttonId"
// or
// cssButtons = "form.className button"; // and loop through button list to find exact button by buttonText
}
Note that I use the CssSelector instead of the XPath to get the button element.
For example, I need a common function that clicks a button given the button text. I don't want to have to keep writing this long code snippet:
(new WebDriverWait(driver, waitSeconds)).until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(CssFormButtonBegin+buttonText+CssFormButtonEnd))).click();
Instead, I would like to use a common function like:
public void clickButton(String buttonText) {
getButton(String buttonText);
}
public void getButton(String buttonText) {
// code that gets the WebElement of button type in CssSelector
// cssDoesNotWork = "button:contains('buttonText')"
// cssWorks = "form.className button#buttonId"
// or
// cssButtons = "form.className button"; // and loop through button list to find exact button by buttonText
}
Note that I use the CssSelector instead of the XPath to get the button element.
Useful Reference
Tuesday, October 30, 2018
Selenium Fireforx - Test with clearing browser Cookies
Today, I need to add a specific test that only works when the Cookie is cleared from the browser. This was much simpler than expected. Why reinvent the wheel?
See details @ https://stackoverflow.com/questions/35403614/clear-browser-cookies-with-selenium-webdriver-java-bindings
See details @ https://stackoverflow.com/questions/35403614/clear-browser-cookies-with-selenium-webdriver-java-bindings
Friday, October 26, 2018
Selenium Testing - My References & Bookmarks
Quickly Learning to be a Software Engineer in Test (SET)
In short, because I am learning so much and coding/testing so fast, I can't remember everything and I need to remember specific things fast and with order. So, this is my page to help me remember these important things for being a Software Engineer in Test (SET) or in simpler titles known as Test Engineer.Online References
Selenium - FindElement(By <CSS Selectors>)
Useful Background Information
Online Tools
Load Testing Tools
Online Blogs
Labels:
test,
test automation,
test engineer
Thursday, October 25, 2018
Journey into SET: Part 3 - Follow Test Engineers
In this part of the journey, it's important to learn from other Testers (or SETs or Test Engineers). Yes, it's important to learn from Developers as well, but sometimes we forget the benefit of learning from other Testers. After all, we discover different things yet having the same overall mission: test the crap out of software! Well, not for any old reason, but with the goal of producing a quality product useful to our users and ourselves.
Anyhow, here are some Testers in the industry that I'm following.
Anyhow, here are some Testers in the industry that I'm following.
Test Engineers
Test Tools
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 - 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
Selenium Firefox - Test using FindByElement( By.ClassName() )
This is very similar to the Test using FindByElement( By.XPath() ).
The change in this article is replacing the use of "xpath" obviously.
[Test Utility Class]
public static Boolean isDisclaimerDisplayed(WebDriver webDriver) {
String modalTitle = webDriver.findByElement(By.className("modal-title").getText();
return modalTitle.equalsIgnoreCase("Notice to All Users");
}
References
https://www.softwaretestingmaterial.com/how-to-locate-element-by-class-name-locator/
https://saucelabs.com/resources/articles/selenium-tips-css-selectors
The change in this article is replacing the use of "xpath" obviously.
[Test Utility Class]
public static Boolean isDisclaimerDisplayed(WebDriver webDriver) {
String modalTitle = webDriver.findByElement(By.className("modal-title").getText();
return modalTitle.equalsIgnoreCase("Notice to All Users");
}
That's it. Cheers!
References
https://www.softwaretestingmaterial.com/how-to-locate-element-by-class-name-locator/
https://saucelabs.com/resources/articles/selenium-tips-css-selectors
Selenium Firefox - Test using FindByElement( By.XPath() )
Today, the goal is to verify the home page for a user after login. Actually, a disclaimer is displayed to the user before the user can access the home page. A modal is displayed with the disclaimer agreement and waits for the user to accept the disclaimer before the application redirects the user to their homepage.
So, the title of the modal include this text: "Notice to All Users".
I want my test to find this modal title and verify that the text is "Notice to All Users". This will also confirm that my login test passes because when I enter an unrecognized username the login dialog continues to display as opposed to showing an error message or error page. (In my opinion, this is poor design of the application and I will fix this if I ever get the time.)
My Code:
[Test Script Class]
@Test
public void testLogin() {
Application.login(webDriver, url, username, password);
boolean isDisplayed = Application.isDisclaimerDisplayed(webDriver);
Assert.assertTrue("User successfully logged into Application.", isDisplayed);
}
[Test Utility Class]
public static Boolean isDisclaimerDisplayed(WebDriver webDriver) {
String xpathRegEx = "//h3[@class='modal-title']";
String modalTitle = webDriver.findByElement(By.xpath(xpathRegEx).getText();
return modalTitle.equalsIgnoreCase("Notice to All Users");
}
One side of Caution here: This is slower than other methods of finding elements like by ID or by Class Name because this method looks through the entire XML formatted HTML document to find the element expected.
References
https://www.softwaretestingmaterial.com/how-to-locate-element-by-xpath-locator/
https://saucelabs.com/resources/articles/selenium-tips-css-selectors
So, the title of the modal include this text: "Notice to All Users".
I want my test to find this modal title and verify that the text is "Notice to All Users". This will also confirm that my login test passes because when I enter an unrecognized username the login dialog continues to display as opposed to showing an error message or error page. (In my opinion, this is poor design of the application and I will fix this if I ever get the time.)
My Code:
[Test Script Class]
@Test
public void testLogin() {
Application.login(webDriver, url, username, password);
boolean isDisplayed = Application.isDisclaimerDisplayed(webDriver);
Assert.assertTrue("User successfully logged into Application.", isDisplayed);
}
[Test Utility Class]
public static Boolean isDisclaimerDisplayed(WebDriver webDriver) {
String xpathRegEx = "//h3[@class='modal-title']";
String modalTitle = webDriver.findByElement(By.xpath(xpathRegEx).getText();
return modalTitle.equalsIgnoreCase("Notice to All Users");
}
One side of Caution here: This is slower than other methods of finding elements like by ID or by Class Name because this method looks through the entire XML formatted HTML document to find the element expected.
References
https://www.softwaretestingmaterial.com/how-to-locate-element-by-xpath-locator/
https://saucelabs.com/resources/articles/selenium-tips-css-selectors
Journey into SET: Part 1
So, I'm getting back into the game of software testing and especially with the new test automation tools and techniques. I'm going to log my journey of catching back up in this field after being in software development (away from testing to purely coding without testing - and I know this is bad). So, let's just add that I'm restoring the best practices of a software engineer.
Nowadays, it seems the new title for software testers is either Software Development/Design Engineer in Test (SDET) or Software Engineer in Test (SET) or similar. The emphasis is on the evolving skills of a tester having the capabilities to develop (or code) meanwhile advancing their techniques of applying best practices in test automation. This makes sense when we consider how the multitude of frameworks for development web application and software tools has also evolved.
Here are some articles to read.
Evolution of the Software Testing role:
One can also gain an understanding of what a test engineer (or SDET or SET) does today by looking up the job qualifications on major tech company career websites including Google (specifically "Test Engineer"), Amazon (spec. "Software Development Engineer in Test"), Microsoft (spec. "Software Design Engineer in Test").
A Quick Recap from Microsoft's Personal Experience
Here's a nice recap from Microsoft on the transition of eliminating the Software Test Engineer (STEs) and creating a "combined engineering" team.
Software Test Design
Similarly to developing any software, developing scripts to test software also should go through the design phase in order to create test structure. This helps with organizing tests to correspond to the software design, finding bugs early in the design process of software development, creating a testing framework for easier ramp-up of new Test Engineers and for easier review of the software development team, and more.
Software Test Design - Problems
First problem I'm interested in is what to name the appendages of the class files especially for the automated test scripts via the browser.
Unit Tests use the appendage "Test" like "HelloWorldTest".
Integration Tests use the appendage "IT" like "HelloWorldIT".
I've seen throughout the Selenium docs the term "AUT" (or application under test) and wonder if I should use this as the appendage for my test scripts via browser like "HelloWorldAUT". But is this sufficient?
Software Test Design - Research
https://dzone.com/articles/design-patterns-in-automation-testing
What is SOLID (Principles)?
https://msdn.microsoft.com/en-us/magazine/dn683797.aspx (dated: May 2014)
*There are a number of terms explained in this article that I really like. For instance, the author says "when I say principle, I'm referring to a feature of the computer code that helps maintain the value of that code."
Software Testing Conferences
Here are some conferences to be aware of with respect to software test automation and the future of testing software.
Software Test Tools
There are a lot of tools from the many articles online that I've read. Not to overwhelm one with reading through all the articles and also knowing that the software tool depends on the software developed, here's a short list of tools that I'm learning and applying.
Leading the list is Selenium as the best, open source tool for testing web applications.
I should really keep track of my progress here. This is getting way too long. So I need to split this step into smaller steps and start publishing.
Nowadays, it seems the new title for software testers is either Software Development/Design Engineer in Test (SDET) or Software Engineer in Test (SET) or similar. The emphasis is on the evolving skills of a tester having the capabilities to develop (or code) meanwhile advancing their techniques of applying best practices in test automation. This makes sense when we consider how the multitude of frameworks for development web application and software tools has also evolved.
Here are some articles to read.
Evolution of the Software Testing role:
- https://www.test-institute.org/Software_Testing_Roles_And_Responsibilities.php
- https://learn.org/articles/How_Does_a_Software_Testing_Engineer_Do.html
- https://www.softwaretestingclass.com/what-is-difference-between-sdet-and-tester/
- https://www.ness.com/significance-of-a-software-development-engineer-in-test-sdet-in-the-digital-economy/
- https://www.cigniti.com/blog/rise-of-the-software-development-engineer-in-test-sdet/
- https://www.guru99.com/software-developer-engineer-test-sdet.html
- https://testing.googleblog.com/2011/01/how-google-tests-software.html
- https://testing.googleblog.com/2011/02/how-google-tests-software-part-two.html
- https://www.testing-whiz.com/blog/8-software-testing-trends-every-tester-should-follow-in-2018
- https://www.upwork.com/hiring/for-clients/top-5-emerging-software-testing-trends-follow-2018/
One can also gain an understanding of what a test engineer (or SDET or SET) does today by looking up the job qualifications on major tech company career websites including Google (specifically "Test Engineer"), Amazon (spec. "Software Development Engineer in Test"), Microsoft (spec. "Software Design Engineer in Test").
A Quick Recap from Microsoft's Personal Experience
Here's a nice recap from Microsoft on the transition of eliminating the Software Test Engineer (STEs) and creating a "combined engineering" team.
Software Test Design
Similarly to developing any software, developing scripts to test software also should go through the design phase in order to create test structure. This helps with organizing tests to correspond to the software design, finding bugs early in the design process of software development, creating a testing framework for easier ramp-up of new Test Engineers and for easier review of the software development team, and more.
Software Test Design - Problems
First problem I'm interested in is what to name the appendages of the class files especially for the automated test scripts via the browser.
Unit Tests use the appendage "Test" like "HelloWorldTest".
Integration Tests use the appendage "IT" like "HelloWorldIT".
I've seen throughout the Selenium docs the term "AUT" (or application under test) and wonder if I should use this as the appendage for my test scripts via browser like "HelloWorldAUT". But is this sufficient?
Software Test Design - Research
https://dzone.com/articles/design-patterns-in-automation-testing
What is SOLID (Principles)?
- Single responsibility
- Open-Closed priniciple: open for extension and closed for modification
- Liskov substitution
- Interface segregation
- Dependency injection
https://msdn.microsoft.com/en-us/magazine/dn683797.aspx (dated: May 2014)
*There are a number of terms explained in this article that I really like. For instance, the author says "when I say principle, I'm referring to a feature of the computer code that helps maintain the value of that code."
Software Testing Conferences
Here are some conferences to be aware of with respect to software test automation and the future of testing software.
Software Test Tools
There are a lot of tools from the many articles online that I've read. Not to overwhelm one with reading through all the articles and also knowing that the software tool depends on the software developed, here's a short list of tools that I'm learning and applying.
Leading the list is Selenium as the best, open source tool for testing web applications.
- Selenium - https://www.seleniumhq.org/docs/
I should really keep track of my progress here. This is getting way too long. So I need to split this step into smaller steps and start publishing.
Monday, October 15, 2018
Loading Properties file for Test Automation
I am trying to load a simple.properties file into my test suite as soon as I run my test automation.
I tried following tutorial on Apache Commons, but I am missing the configuration2 package. I don't have time to download this and install since I'm working on a secure network.
https://commons.apache.org/proper/commons-configuration/userguide/howto_properties.html
To be exact, I need the configuration2 package for the Parameters class.
https://commons.apache.org/proper/commons-configuration/apidocs/org/apache/commons/configuration2/builder/fluent/Parameters.html
Okay, now what?
Well, let's first use basic Java to load a Properties file and test it.
I can't remember the website where I got this code from, but it is similar to the basic Java tutorial with the exception of using a BufferedReader instead of the InputStreamReader or the like. I added this into my init() method.
private Properties properties;
@Before
public void init() {
Log.Info("Starting my test automation...");
BufferedReader reader;
try {
reader = new BufferedReader( new FileReader( "src/test/resources/simple.properties"));
properties = new Properties();
try {
properties.load(reader);
reader.close();
} catch (IOException ioEx) {
ioEx.printStackTrace();
}
} catch (FileNotFoundException fileEx) {
fileEx.printStackTrace();
throw new RuntimeException("simple.properties file not found!");
}
}
// Note, inside of my simple.properties file is:
// testword = hello
@Test
public void testPropertiesFilesLoaded() {
Assert.assertEquals(properties.get("testword"), "hello");
}
I ran this from the command line using Maven.
$ mvn -Dtest=SimpleTestAUT test -pl :app-ui
And the test passed! Yay!
Now, I need to know how to really use this properties file across my test suite. I have a Sample1AUT.java and Sample2AUT.java. In Sample1AUT.java, I have the following.
@BeforeClass
public static void setup() {
MyProperties.loadProperties("myPropertiesFileName");
}
@Test
public void testPropertiesLoaded() {
Assert.assertEquals("user", MyProperties.getProperty("biz.username"));
}
This is what my MyProperties class looks like.
public class MyProperties {
static Properties properties;
public static void loadProperties(String fileName) {
BufferedReader reader;
try {
reader = new BufferedReader( new FileReader( "src/test/resources/"+fileName+".properties"));
properties = new Properties();
try {
properties.load(reader);
reader.close();
} catch (IOException ioEx) {
ioEx.printStackTrace();
}
} catch (FileNotFoundException fileEx) {
fileEx.printStackTrace();
throw new RuntimeException(fileName+".properties file not found!");
}
}
public static String getProperty(String key) {
return (String) properties.get(key);
}
}
It worked, yay!
What I need to try next is loading Properties file via Krausening in case my "test/resources" folder is not deployed with the WAR including the Test Suite.
I tried following tutorial on Apache Commons, but I am missing the configuration2 package. I don't have time to download this and install since I'm working on a secure network.
https://commons.apache.org/proper/commons-configuration/userguide/howto_properties.html
To be exact, I need the configuration2 package for the Parameters class.
https://commons.apache.org/proper/commons-configuration/apidocs/org/apache/commons/configuration2/builder/fluent/Parameters.html
Okay, now what?
Well, let's first use basic Java to load a Properties file and test it.
I can't remember the website where I got this code from, but it is similar to the basic Java tutorial with the exception of using a BufferedReader instead of the InputStreamReader or the like. I added this into my init() method.
private Properties properties;
@Before
public void init() {
Log.Info("Starting my test automation...");
BufferedReader reader;
try {
reader = new BufferedReader( new FileReader( "src/test/resources/simple.properties"));
properties = new Properties();
try {
properties.load(reader);
reader.close();
} catch (IOException ioEx) {
ioEx.printStackTrace();
}
} catch (FileNotFoundException fileEx) {
fileEx.printStackTrace();
throw new RuntimeException("simple.properties file not found!");
}
}
// Note, inside of my simple.properties file is:
// testword = hello
@Test
public void testPropertiesFilesLoaded() {
Assert.assertEquals(properties.get("testword"), "hello");
}
I ran this from the command line using Maven.
$ mvn -Dtest=SimpleTestAUT test -pl :app-ui
And the test passed! Yay!
Now, I need to know how to really use this properties file across my test suite. I have a Sample1AUT.java and Sample2AUT.java. In Sample1AUT.java, I have the following.
@BeforeClass
public static void setup() {
MyProperties.loadProperties("myPropertiesFileName");
}
@Test
public void testPropertiesLoaded() {
Assert.assertEquals("user", MyProperties.getProperty("biz.username"));
}
This is what my MyProperties class looks like.
public class MyProperties {
static Properties properties;
public static void loadProperties(String fileName) {
BufferedReader reader;
try {
reader = new BufferedReader( new FileReader( "src/test/resources/"+fileName+".properties"));
properties = new Properties();
try {
properties.load(reader);
reader.close();
} catch (IOException ioEx) {
ioEx.printStackTrace();
}
} catch (FileNotFoundException fileEx) {
fileEx.printStackTrace();
throw new RuntimeException(fileName+".properties file not found!");
}
}
public static String getProperty(String key) {
return (String) properties.get(key);
}
}
It worked, yay!
What I need to try next is loading Properties file via Krausening in case my "test/resources" folder is not deployed with the WAR including the Test Suite.
References
Subscribe to:
Posts (Atom)