Challenges in test automation for web apps

29
Challenges in Test Automation for Web Apps Sudara Madushan Fernando, Graduate Trainee, hSenid Business Solutions.

Transcript of Challenges in test automation for web apps

Page 1: Challenges in test automation for web apps

Challenges in Test Automation for Web Apps

Sudara Madushan Fernando,

Graduate Trainee, hSenid Business Solutions.

Page 2: Challenges in test automation for web apps

Scripting Time

Keeping in touch with the Browser

Changes in the System

Dynamic elementsCoding without QA

Copy (Ctrl + C) and Paste (Ctrl + V)

Maintaining the maintainability100% success rate

Page 3: Challenges in test automation for web apps

Scripting Time• Scripting Time = Time you take to code a test case NOT the time it takes to run

the test case

• Why we need to spend less time in scripting and lots of time in running them? Because it is what QA does!

• The biggest disadvantage Automation has against Manual Testing is the time “wasted” on scripting

Results

Scripting time

PR

OB

LEM

Page 4: Challenges in test automation for web apps

Scripting TimeS

OLU

TIO

N

• In most of the test cases the steps of doing something is repeating Test case 01 – Test if a user can apply a leave on a holiday Test case 02 – Test if a user can apply a leave on a working day

• Understanding this, Selenium Developers introduced The Page Object Model

• Up to

60% less time in scripting!

Page 5: Challenges in test automation for web apps

Copy and Paste• Windows’ highly used feature is NOT going to help us in test scripting!

• It WILL make the test cases less maintainable. PR

OB

LEMStep

01• Log in

Step 02

• Apply leave

Step 03

• Capture error message

Step 01

• Log in

Step 02

• Apply leave

Step 03

• Capture success

• message

Page 6: Challenges in test automation for web apps

Copy (Ctrl + C) and Paste (Ctrl + V)PR

OB

LEM

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

• What will happen if an ID is changed?

• What will happen if steps of doing “it” is changed?

Page 7: Challenges in test automation for web apps

SO

LUTIO

N

• Introduce a third party – Intermediary class for managing “actions”

Copy (Ctrl + C) and Paste (Ctrl + V)

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Page 8: Challenges in test automation for web apps

Keeping in touch with the Browser• In Web App automation – TWO things are happening parallel

Getting web page elements and rendering them by the Browser Initializing and running test scripts by the Selenium Web Driver

• If one is faster than the other OR if one is slower than the other, test case IS FAILING!

• Selenium will NEVER wait for the browser UNLESS we ask it to.

• Browser has no idea that the Selenium in running behind – so it won’t wait either

• We have to bridge the GAP!

PR

OB

LEM

Page 9: Challenges in test automation for web apps

Keeping in touch with the BrowserPR

OB

LEM

IE - HRM - hSenidhttp://hrm.hsenid.lk

Log in

Username

Password

Nunit – GUI

Driver.navigateTo(http://hrm.hsenid.lk);

Driver.FindElement(By.Id(“username”));

Driver.FindElement(By.Id(“password”));

Driver.FindElement(By.Id(“login_btn”));

Page 10: Challenges in test automation for web apps

Keeping in touch with the BrowserPR

OB

LEM

IE - HRM - hSenidhttp://hrm.hsenid.lk

Log in

Username

Password

Nunit – GUI

Driver.navigateTo(http://hrm.hsenid.lk);

Driver.FindElement(By.Id(“username”));

Driver.FindElement(By.Id(“password”));

Driver.FindElement(By.Id(“login_btn”));

Page 11: Challenges in test automation for web apps

Keeping in touch with the BrowserS

UG

GES

TIO

N

IE - HRM - hSenidhttp://hrm.hsenid.lk

Log in

Username

Password

Nunit – GUI

Driver.navigateTo(http://hrm.hsenid.lk);

Thread.Sleep(5000);

Driver.FindElement(By.Id(“username”));

Driver.FindElement(By.Id(“password”));

Driver.FindElement(By.Id(“login_btn”));

Using Thread.Sleep()

Page 12: Challenges in test automation for web apps

Keeping in touch with the BrowserS

UG

GES

TIO

N

IE - HRM - hSenidhttp://hrm.hsenid.lk

Log in

Username

Password

Nunit – GUI

Driver.navigateTo(http://hrm.hsenid.lk);

Thread.Sleep(5000);

Driver.FindElement(By.Id(“username”));

Driver.FindElement(By.Id(“password”));

Driver.FindElement(By.Id(“login_btn”));

What if we are waiting 5 seconds and element takes 8 seconds to load?

Page 13: Challenges in test automation for web apps

Keeping in touch with the BrowserS

UG

GES

TIO

N

IE - HRM - hSenidhttp://hrm.hsenid.lk

Log in

Username

Password

Nunit – GUI

Driver.navigateTo(http://hrm.hsenid.lk);

Thread.Sleep(10000);

Driver.FindElement(By.Id(“username”));

Driver.FindElement(By.Id(“password”));

Driver.FindElement(By.Id(“login_btn”));

If it is the case then we can wait for 10 seconds!

Page 14: Challenges in test automation for web apps

Keeping in touch with the BrowserS

UG

GES

TIO

N

IE - HRM - hSenidhttp://hrm.hsenid.lk

Log in

Username

Password

Nunit – GUI

Driver.navigateTo(http://hrm.hsenid.lk);

Thread.Sleep(10000);

Driver.FindElement(By.Id(“username”));

Driver.FindElement(By.Id(“password”));

Driver.FindElement(By.Id(“login_btn”));

What if it loads in 2 seconds?

Page 15: Challenges in test automation for web apps

SO

LUTIO

N

• We should ask the Thread to WAIT rather than SLEEPING!

• If the Thread can wait for the number of seconds that the element takes to load, that is our SOLUTION

• But we will NEVER be able to predict how long it takes to load an element, might be 2 seconds, 5 seconds or even 12 seconds!

• Selenium has the answer - WebDriverWait

Keeping in touch with the Browser

Page 16: Challenges in test automation for web apps

SO

LUTIO

NKeeping in touch with the Browser

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(15));

wait.Until(b => driver.FindElement(By.Id(“username”).Displayed);

Page 17: Challenges in test automation for web apps

Keeping in touch with the BrowserS

OLU

TIO

N

IE - HRM - hSenidhttp://hrm.hsenid.lk

Log in

Username

Password

Nunit – GUI

Driver.navigateTo(http://hrm.hsenid.lk);

wait.Until(b =>

(“username”).Displayed);

Driver.FindElement(By.Id(“username”));

Driver.FindElement(By.Id(“password”));

Driver.FindElement(By.Id(“login_btn”));

Now it will start executing, as soon as the element is loaded

Page 18: Challenges in test automation for web apps

Dynamic Elements• Auto generating elements are called Dynamically generated elements, no body

can predict that dynamic elements actually exist in a page until the page is rendered.

• Catching a dynamic element is the worst nightmare of an automation scriptor.

• To make things worse, sometimes we may not be able to identify an element as a dynamic element.

• If you are catching a dynamic element, your test case MAY FAIL or PASS, depending on the status of that element.

PR

OB

LEM

Page 19: Challenges in test automation for web apps

Dynamic ElementsPR

OB

LEM

Page 20: Challenges in test automation for web apps

Dynamic ElementsPR

OB

LEM

Page 21: Challenges in test automation for web apps

SO

LUTIO

N

• Since the ID of a dynamic element can change, try to use other stable locators – such as the Tag name

• We might have to depend on the code structure of the web page or the DOM (Document Object Model)

Dynamic Elements

IList<IWebElement> rows = driver.FindElement(By.Id(“table”))

.FindElements(By.Tagname(“tr”));foreach(IWebElement row in rows){

Cells = element.FindElements(By.Tagname(“td”));}

Page 22: Challenges in test automation for web apps

Maintaining the Maintainability• Is “once written – it’s over” working for automation scripts?

• When the system is updated, do we have to start from the beginning? If we have to, then we are spending a lot of time on scripting!

• We will have to maintain the scripts doing changes as and when it happens on the system.

PR

OB

LEM

Page 23: Challenges in test automation for web apps

SO

LUTIO

N

• The System is changing all the time. But are the test cases?

• “Check if a user can apply a leave” – won’t change as long as our system is allowing a user to apply a leave

• DEFINITION of a test case is the same – IMPLEMENTATION is different

• So DEFINE in one class, and IMPLEMENT in another class, it is what Page Object Model encourages us

• Have a class for each Page, code the activities that page can do in that class

Maintaining the Maintainability

Page 24: Challenges in test automation for web apps

SO

LUTIO

NMaintaining the Maintainability

Page 25: Challenges in test automation for web apps

SO

LUTIO

NMaintaining the Maintainability

Page 26: Challenges in test automation for web apps

Coding without QAPR

OB

LEM

• Nobody can code 100% bug free software – but automation scripters have to!

• Automation Scripts are not sent for QA – if it is, it will be an additional burden on the team

• Coding 100% bug free software is a challenge it self, but doing that without QA?

Page 27: Challenges in test automation for web apps

SO

LUTIO

N

• You will laugh at me when I say that the solution is to send the scripts for QA – So I won’t!

• If you complete a test case, run it once and say “I am done” – I will laugh at you!

• The more number of times you run your test case, the more perfect it is going to be.

• Run and run and run, you will find bugs yourself, this eliminates the need for QA**.

Coding without QA

**only applies to Automation scripts – if you think you can do the same with the System, we all will laugh at you!

Page 28: Challenges in test automation for web apps

Questions?PR

OB

LEM

Page 29: Challenges in test automation for web apps

Thank you!