104
KISS Automation @yashaka itlabs.net.ua

QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

Embed Size (px)

Citation preview

Page 1: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

KISS Automation

@yashakaitlabs.net.ua

Page 2: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

AfterwordsThere are good practices in context,

but there are no best practices.

(c) Cem Kaner, James Bach

Page 3: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

Afterwords PrefaceThere are good practices in context,

but there are no best practices.

(c) Cem Kaner, James Bach

Page 4: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

KISS?

Page 5: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

Keep It Simple Stupid!

Page 6: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

Web UI Automation…

Page 7: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

Selenium vs Wrappers

Page 8: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

Wait for text

Page 9: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

public class ExamplePage{ @FindBy(css = "#element") WebElement element;}

...

WebDriver driver = new FirefoxDriver();ExamplePage page = PageFactory.initElements(driver, ExamplePage.class);(new WebDriverWait(driver, 6)).until(textToBePresentInElement(page.element, ":-*"));

Wait for text

Page 10: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

public class ExamplePage{ @FindBy(css = "#element") WebElement element;}

...

WebDriver driver = new FirefoxDriver();ExamplePage page = PageFactory.initElements(driver, ExamplePage.class);(new WebDriverWait(driver, 6)).until(textToBePresentInElement(page.element, ":-*"));

Wait for text

Page 11: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

public class ExamplePage{ @FindBy(css = "#element") WebElement element;}

...

WebDriver driver = new FirefoxDriver();ExamplePage page = PageFactory.initElements( driver, ExamplePage.class);(new WebDriverWait(driver, 6)).until( textToBePresentInElement(page.element, ":-*"));

Page 12: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

public class ExamplePage{ @FindBy(css = "#element") WebElement element;}

...

WebDriver driver = new FirefoxDriver();ExamplePage page = PageFactory.initElements( driver, ExamplePage.class);(new WebDriverWait(driver, 6)).until( textToBePresentInElement(page.element, ":-*"));

Page 13: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

Wait for text

Page 14: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

Wait for text

SelenideElement element = $(“#element"); ...element.shouldHave(text(":-*"));

Page 15: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

Not mandatory, still possible…

Page 16: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

Not mandatory, still possible…public class ExamplePage{ WebElement element = $(“#element");} ... ExamplePage page = new ExamplePage(); page.element.shouldHave(text(":-*"));

Page 17: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

WrappersSelenium

Page 18: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

public class ExamplePage{ @FindBy(css = "#element") WebElement element;} ... WebDriver driver = new FirefoxDriver();ExamplePage page = PageFactory.initElements( driver, ExamplePage.class);(new WebDriverWait(driver, 6)).until( textToBePresentInElement(page.element, ":-*"));

SelenideElement element = $(“#element"); ...element.shouldHave(text(":-*"));vs

WrappersSelenium

Page 19: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

public class ExamplePage{ @FindBy(css = "#element") WebElement element;} ... WebDriver driver = new FirefoxDriver();ExamplePage page = PageFactory.initElements( driver, ExamplePage.class);(new WebDriverWait(driver, 6)).until( textToBePresentInElement(page.element, ":-*"));

SelenideElement element = $(“#element"); ...element.shouldHave(text(":-*"));vs

WrappersSelenium

Test logicTest logic messed up with tech details

Page 20: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

public class ExamplePage{ @FindBy(css = "#element") WebElement element;} ... WebDriver driver = new FirefoxDriver();ExamplePage page = PageFactory.initElements( driver, ExamplePage.class);(new WebDriverWait(driver, 6)).until( textToBePresentInElement(page.element, ":-*"));

SelenideElement element = $(“#element"); ...element.shouldHave(text(":-*"));vs

WrappersSelenium

Test logicTest logic messed up with tech details

Page 21: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

public class ExamplePage{ @FindBy(css = "#element") WebElement element;} ... WebDriver driver = new FirefoxDriver();ExamplePage page = PageFactory.initElements( driver, ExamplePage.class);(new WebDriverWait(driver, 6)).until( textToBePresentInElement(page.element, ":-*"));

SelenideElement element = $(“#element"); ...element.shouldHave(text(":-*"));vs

WrappersSelenium

may be SlowerFast

Page 22: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

public class ExamplePage{ @FindBy(css = "#element") WebElement element;} ... WebDriver driver = new FirefoxDriver();ExamplePage page = PageFactory.initElements( driver, ExamplePage.class);(new WebDriverWait(driver, 6)).until( textToBePresentInElement(page.element, ":-*"));

SelenideElement element = $(“#element"); ...element.shouldHave(text(":-*"));vs

WrappersSelenium

may be SlowerFast

Page 23: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

End to End vs “Unit”

Page 24: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"
Page 25: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

def test_task_life_cycle(): given_at_todomvc() add("a") edit("a", "a edited") toggle("a edited") filter_active() assert_no_tasks() filter_completed() delete("a edited") assert_no_tasks() #...

End to End Scenario

Page 26: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

def test_task_life_cycle(): given_at_todomvc() add("a") edit("a", "a edited") toggle("a edited") filter_active() assert_no_tasks() filter_completed() delete("a edited") assert_no_tasks() #...

End to End Scenario

implicit checks

Page 27: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

“Unit” / “1-feature-per-test” style

Page 28: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

def test_add(): given_at_todomvc() add("a", "b") assert_tasks("a", "b") assert_items_left(2)

“Unit” / “1-feature-per-test” style

Page 29: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

def test_add(): given_at_todomvc() add("a", "b") assert_tasks("a", "b") assert_items_left(2)

“Unit” / “1-feature-per-test” styledef test_delete(): given_at_todomvc("a", "b", "c") delete("b") assert_tasks("a", "c") assert_items_left(2)

Page 30: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

def test_add(): given_at_todomvc() add("a", "b") assert_tasks("a", "b") assert_items_left(2)

“Unit” / “1-feature-per-test” styledef test_delete(): given_at_todomvc("a", "b", "c") delete("b") assert_tasks("a", "c") assert_items_left(2)

def test_edit(): given_at_todomvc("a", "b", "c") edit("c", "c edited") assert_tasks("a", "b", "c edited") assert_items_left(3)

Page 31: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

def test_add(): given_at_todomvc() add("a", "b") assert_tasks("a", "b") assert_items_left(2)

“Unit” / “1-feature-per-test” styledef test_delete(): given_at_todomvc("a", "b", "c") delete("b") assert_tasks("a", "c") assert_items_left(2)

def test_edit(): given_at_todomvc("a", "b", "c") edit("c", "c edited") assert_tasks("a", "b", "c edited") assert_items_left(3)

def test_toggle(): #...

Page 32: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

def test_add(): given_at_todomvc() add("a", "b") assert_tasks("a", "b") assert_items_left(2)

“Unit” / “1-feature-per-test” styledef test_delete(): given_at_todomvc("a", "b", "c") delete("b") assert_tasks("a", "c") assert_items_left(2)

def test_edit(): given_at_todomvc("a", "b", "c") edit("c", "c edited") assert_tasks("a", "b", "c edited") assert_items_left(3)

def test_toggle(): #...

#...

Page 33: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

def test_add(): given_at_todomvc() add("a", "b") assert_tasks("a", "b") assert_items_left(2)

“Unit” / “1-feature-per-test” styledef test_delete(): given_at_todomvc("a", "b", "c") delete("b") assert_tasks("a", "c") assert_items_left(2)

def test_edit(): given_at_todomvc("a", "b", "c") edit("c", "c edited") assert_tasks("a", "b", "c edited") assert_items_left(3)

def test_toggle(): #...

#...

Page 34: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

“Unit”/“Feature”E2E

Page 35: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

vs

“Unit”/“Feature”E2Edef test_task_life_cycle(): given_at_todomvc() add("a") edit("a", "a edited") toggle("a edited") filter_active() assert_no_tasks() filter_completed() delete("a edited") assert_no_tasks() #...

def test_add(): given_at_todomvc() add("a", "b") assert_tasks("a", "b") assert_items_left(2)

def test_delete(): #...

#...

Page 36: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

vs

“Unit”/“Feature”E2E

SimpleEasy

def test_task_life_cycle(): given_at_todomvc() add("a") edit("a", "a edited") toggle("a edited") filter_active() assert_no_tasks() filter_completed() delete("a edited") assert_no_tasks() #...

def test_add(): given_at_todomvc() add("a", "b") assert_tasks("a", "b") assert_items_left(2)

def test_delete(): #...

#...

Page 37: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

Simple is not Easy

Page 38: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

–Rich Hickey

“Simple Made Easy”

Page 39: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

“Unit”/“Feature”E2E

Page 40: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

vs

“Unit”/“Feature”E2E

+ more coverage

+ in less time

+ in case of bugs, gives more complete report

+ easier to identify reason from the report

=>

+ less time and efforts in support

+ with less efforts during POC implementation

+ integration coverage

Page 41: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

vs

“Unit”/“Feature”E2E

SimpleEasy

+ more coverage

+ in less time

+ in case of bugs, gives more complete report

+ easier to identify reason from the report

=>

+ less time and efforts in support

+ with less efforts during POC implementation

+ integration coverage

Page 42: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

vs

“Unit”/“Feature”E2E

SimpleEasy

+ more coverage

+ in less time

+ in case of bugs, gives more complete report

+ easier to identify reason from the report

=>

+ less time and efforts in support

+ with less efforts during POC implementation

+ integration coverage

Page 43: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

vs

“Unit”/“Feature”E2E

SimpleEasy

+ more coverage

+ in less time

+ in case of bugs, gives more complete report

+ easier to identify reason from the report

=>

+ less time and efforts in support

+ with less efforts during POC implementation

+ integration coverage

Page 44: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

vs Simple“Pretty”

Reports

Page 45: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

public class TodoMVCTest { @Test public void testTaskLifeCycle(){ givenAtTodoMVC(); add("a"); toggle("a"); filterActive(); assertNoTasks(); filterCompleted(); edit("a", "a edited"); toggle("a edited"); assertNoTasks(); //... }

@Test public void testAddTasks(){ givenAtTodoMVC(); add("a", "b", "c"); assertTasks("a", "b", "c"); assertItemsLeft(3); } @Test public void testDeleteTask(){ givenAtTodoMVC("a", "b", "c"); delete("b"); assertTasks("a", "c"); assertItemsLeft(2); } //...}

Page 46: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

Simple

Page 47: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.18.1</version> <configuration> <argLine> -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar" </argLine> <properties> <property> <name>listener</name> <value>ru.yandex.qatools.allure.junit.AllureRunListener</value> </property> </properties> </configuration> <dependencies> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>${aspectj.version}</version> </dependency> </dependencies> </plugin>

Allure reporting

<reporting> <excludeDefaults>true</excludeDefaults> <plugins> <plugin> <groupId>ru.yandex.qatools.allure</groupId> <artifactId>allure-maven-plugin</artifactId> <version>2.0</version> </plugin> </plugins></reporting>

Page 48: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

@Steppublic static void add(String... taskTexts) { for(String text: taskTexts){ newTodo.setValue(text).pressEnter(); }}@Steppublic static void filterActive(){ $(By.linkText("Active")).click();}

//...

Allure reporting

Page 49: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

“Pretty” with Allure

Page 50: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

vs

SimplePretty

SimpleMore configs & annotations

Reporting

Page 51: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

vs

SimplePretty

Enough for “Unit”Good for E2E

Reporting

Page 52: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

BDD vs xUnit

Page 53: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

BDD

Page 54: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

BDD

Page 55: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

xUnitBDD

Page 56: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

vs

xUnitBDD1. Write scenarios with steps

2. Define steps

2.1 Introduce state

3. Map steps

4. Configure Runner

5. Run

6. Get pretty reports

1. Write tests with steps

2. Define steps

3. Run

4. Get reports

Page 57: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

vs

xUnitBDD1. Write scenarios with steps

2. Define steps

2.1 Introduce state

3. Map steps

4. Configure Runner

5. Run

6. Get pretty reports

1. Write tests with steps

2. Define steps

3. Run

4. Get reportsstill pretty with Allure

Page 58: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

vs

xUnitBDD

Simple & Easy? :)

1. Write scenarios with steps

2. Define steps

2.1 Introduce state

3. Map steps

4. Configure Runner

5. Run

6. Get pretty reports

1. Write tests with steps

2. Define steps

3. Run

4. Get reportsstill pretty with Allure

Page 59: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

vs

xUnitBDD

Simple & Easy? :)

1. Write scenarios with steps

2. Define steps

2.1 Introduce state

3. Map steps

4. Configure Runner

5. Run

6. Get pretty reports

1. Write tests with steps

2. Define steps

3. Run

4. Get reportsstill pretty with Allure

Page 60: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

vs

xUnitBDD

Less coding, Full power of PLNo vars & return from steps

1. Write tests with steps

2. Define steps

3. Run

4. Get reportsstill pretty with Allure

Page 61: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

vs

xUnitBDD

Less coding, Full power of PLNo vars & return from steps

1. Write tests with steps

2. Define steps

3. Run

4. Get reportsstill pretty with Allure

Page 62: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

vs

xUnitBDD

Less coding, Full power of PLMonkeys-friendly

1. Write tests with steps

2. Define steps

3. Run

4. Get reportsstill pretty with Allure

Page 63: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

vs

xUnitBDD

Less coding, Full power of PLMonkeys-friendly

1. Write tests with steps

2. Define steps

3. Run

4. Get reportsstill pretty with Allure

Page 64: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

PageModules

vs

PageObjects

Page 65: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

PageModules

vsModularOOP

PageObjects

Page 66: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

from pages import tasks

def test_filter_tasks():

tasks.visit() tasks.add("a", "b", "c") tasks.should_be("a", "b", "c") ...

from pages.tasks import TasksPage

def test_filter_tasks(): tasks = TasksPage() tasks.visit() tasks.add("a", "b", "c") tasks.should_be("a", "b", "c") ...

PageModulesPageObjects

ModularOOP

Page 67: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

class TasksPage: def __init__(self): self.tasks = ss("#todo-list>li") def visit(self): tools.visit('https://todomvc4tasj.herokuapp.com/') ... def should_be(self, *task_texts): self.tasks.filterBy(visible).should_have(exact_texts(*task_texts)) ...

PageObjects

OOP

Page 68: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

#tasks.py

tasks = ss("#todo-list>li")def visit(): tools.visit('https://todomvc4tasj.herokuapp.com/')

...

def should_be(*task_texts): tasks.filterBy(visible).should_have(exact_texts(*task_texts))

...

PageModules

Modular

Page 69: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

PageModules

vs

ModularOOP

PageObjects

Page 70: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

PageModules

vs

ModularOOP

PageObjects

+ simple

+ easy

+ “newbies” friendly

Page 71: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

PageModules

vs

ModularOOP

PageObjects

+ ? + simple

+ easy

+ “newbies” friendly

Page 72: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

PageModules

vs

ModularOOP

PageObjects

+ ? + simple

+ easy

+ “newbies” friendly+ parallelised tests

Page 73: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

PageModules

vs

ModularOOP

PageObjects

+ ? + simple

+ easy

+ “newbies” friendly+ parallelised tests

(where there is no automatic driver management per

thread)

Page 74: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

Pages of Widgets

vs

Plain Pages

Page 75: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

Pages of Widgets

vs

OOP Modular/Procedural

Plain Pages

Page 76: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

OOP

Pages of “plural” Widgets: Usagedef test_nested_custom_selements(): given_active("a", "b") main = TodoMVC("#todoapp") main.tasks.find(text("b")).toggle() main.clear_completed() main.tasks.assure(texts("a"))

Page 77: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

OOP

Pages of “plural” Widgets: Usagedef test_nested_custom_selements(): given_active("a", "b") main = TodoMVC("#todoapp") main.tasks.find(text("b")).toggle() main.clear_completed() main.tasks.assure(texts("a"))

Page 78: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

OOP

Pages of “plural” Widgets: Usagedef test_nested_custom_selements(): given_active("a", "b") main = TodoMVC("#todoapp") main.tasks.find(text("b")).toggle() main.clear_completed() main.tasks.assure(texts("a"))

Page 79: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

OOP

Pages as Widgets: Usagedef test_nested_custom_selements(): given_active("a", "b") main = TodoMVC("#todoapp") main.tasks.find(text("b")).toggle() main.clear_completed() main.tasks.assure(texts("a"))

Page 80: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

Pages (as widgets) of “plural” Widgets: Implementation

OOP

class TodoMVC(SElement): def init(self): self.tasks = ss("#todo-list>li").of(self.Task) def clear_completed(self): s(“#clear-completed").click() return self class Task(SElement): def toggle(self): self.s(".toggle").click() return self

Page 81: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

Pages (as widgets) of “plural” Widgets: Implementation

OOP

class TodoMVC(SElement): def init(self): self.tasks = ss("#todo-list>li").of(self.Task) def clear_completed(self): s(“#clear-completed").click() return self class Task(SElement): def toggle(self): self.s(".toggle").click() return self

Page 82: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

Pages (as widgets) of “plural” Widgets: Implementation

OOP

class TodoMVC(SElement): def init(self): self.tasks = ss("#todo-list>li").of(self.Task) def clear_completed(self): s(“#clear-completed").click() return self class Task(SElement): def toggle(self): self.s(".toggle").click() return self

Page 83: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

Pages (as widgets) of “plural” Widgets: Implementation

OOP

class TodoMVC(SElement): def init(self): self.tasks = ss("#todo-list>li").of(self.Task) def clear_completed(self): s(“#clear-completed").click() return self class Task(SElement): def toggle(self): self.s(".toggle").click() return self

Page 84: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

Pages (as widgets) of “plural” Widgets: Implementation

OOP

class TodoMVC(SElement): def init(self): self.tasks = ss("#todo-list>li").of(self.Task) def clear_completed(self): s(“#clear-completed").click() return self class Task(SElement): def toggle(self): self.s(".toggle").click() return self

Page 85: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

Pages (as widgets) of “plural” Widgets: Implementation

OOP

class TodoMVC(SElement): def init(self): self.tasks = ss("#todo-list>li").of(self.Task) def clear_completed(self): s(“#clear-completed").click() return self class Task(SElement): def toggle(self): self.s(".toggle").click() return self

Page 86: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

Pages (as widgets) of “plural” Widgets: Implementationclass TodoMVC(SElement): def init(self): self.tasks = ss("#todo-list>li").of(self.Task) def clear_completed(self): s(“#clear-completed").click() return self class Task(SElement): def toggle(self): self.s(".toggle").click() return self OOP

Page 87: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

Plain Pages: Usageimport tasks

def test_nested_custom_selements(): given_active("a", "b") tasks.toggle("b") tasks.clear_completed() tasks.shouldBe("a")

Procedural

Page 88: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

Plain Pages: Usageimport tasks

def test_nested_custom_selements(): given_active("a", "b") tasks.toggle("b") tasks.clear_completed() tasks.shouldBe("a")

Procedural

Page 89: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

Plain Pages: Implementation#tasks.py

tasks = ss("#todo-list>li")def toggle(task_text): tasks.findBy(exact_text(task_text).s(".toggle").click()

...

def should_be(*task_texts): tasks.filterBy(visible).should_have(exact_texts(*task_texts))

... Procedural

Page 90: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

OOP

Pages of “singular” Widgets: Usagedef test_nested_custom_selements(): given_active("a", "b") main = TodoMVC("#todoapp") main.tasks.find(text("b")).toggle() main.clear_completed() main.tasks.assure(texts("a")) main.footer.assure_items_left(1)

Page 91: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

OOP

Pages of “singular” Widgets: Usagedef test_nested_custom_selements(): given_active("a", "b") main = TodoMVC("#todoapp") main.tasks.find(text("b")).toggle() main.clear_completed() main.tasks.assure(texts("a")) main.footer.assure_items_left(1)

Page 92: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

OOP

Pages of “singular” Widgets: Usagedef test_nested_custom_selements(): given_active("a", "b") main = TodoMVC("#todoapp") main.tasks.find(text("b")).toggle() main.clear_completed() main.tasks.assure(texts("a")) main.footer.assure_items_left(1)

Page 93: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

OOP

Pages of “singular” Widgets: Implementationclass TodoMVC(SElement): def init(self): self.tasks = ss("#todo-list>li").of(self.Task) self.footer = self.Footer("#footer") ... class Footer(SElement): def init(self): self.clear_completed = self.s("#clear-completed") def assure_items_left(self, number_of_active_tasks): self.s("#todo-count>strong").assure(exact_text(str(number_of_active_tasks)))

Page 94: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

OOP

Pages of “singular” Widgets: Implementationclass TodoMVC(SElement): def init(self): self.tasks = ss("#todo-list>li").of(self.Task)

self.footer = self.Footer("#footer") ... class Footer(SElement): def init(self): self.clear_completed = self.s("#clear-completed") def assure_items_left(self, number_of_active_tasks): self.s("#todo-count>strong").assure(exact_text(str(number_of_active_tasks)))

Page 95: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

Pages of “singular” Widgets: Implementationclass TodoMVC(SElement): def init(self): self.tasks = ss("#todo-list>li").of(self.Task)

self.footer = self.Footer("#footer") ... class Footer(SElement): def init(self): self.clear_completed = self.s("#clear-completed") def assure_items_left(self, number_of_active_tasks): self.s("#todo-count>strong").assure(exact_text(str(number_of_active_tasks)))

Page 96: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

Plain Pages: Usagedef test_nested_custom_selements(): given_active("a", "b") tasks.toggle("b") tasks.clear_completed() tasks.shouldBe(“a") footer.assert_items_left(1)

Modular

Page 97: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

Plain Pages: Implementation#tasks.py tasks = ss("#todo-list>li")def toggle(task_text): tasks.findBy(exact_text(task_text).s(".toggle").click() ...

Modular

#footer.py def assure_items_left(self, number_of_active_tasks): s("#todo-count>strong").assure(exact_text(str(number_of_active_tasks))) ...

Page 98: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

Plain Pages

vs

Procedural/ModularOOP

Pages with Widgets

Page 99: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

Plain Pages

vs

Procedural/ModularOOP

Pages with Widgets

+ simple

+ easy

+ “newbies” friendly

+ less code

+ visible

Page 100: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

Plain Pages

vs

Procedural/ModularOOP

Pages with Widgets

+ ?

+ simple

+ easy

+ “newbies” friendly

+ less code

+ visible

Page 101: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

Plain Pages

vs

Procedural/ModularOOP

Pages with Widgets

+ ?

+ simple

+ easy

+ “newbies” friendly

+ less code

+ visible

+ for complex UI with many “plural” widgets

Page 102: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

AfterwordsThere are good practices in context,

but there are no best practices.

(c) Cem Kaner, James Bach

Page 103: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

Q&A

Page 104: QA Lab: тестирование ПО. Яков Крамаренко: "KISS Automation"

Thank you!

github.com/yashaka slideshare.net/yashaka

gitter.im/yashaka/better-selenium youtube.com/c/ItlabsNetUa

@yashakaitlabs.net.ua