Top Banner
Web UI Tests Examples with Selenide, nSelene, Selene & Capybara
21

Web ui tests examples with selenide, nselene, selene & capybara

Jan 07, 2017

Download

Technology

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Web ui tests examples with  selenide, nselene, selene & capybara

Web UI Tests Examples with

Selenide, nSelene, Selene & Capybara

Page 2: Web ui tests examples with  selenide, nselene, selene & capybara

http://todomvc4tasj.herokuapp.com

Page 3: Web ui tests examples with  selenide, nselene, selene & capybara

Tests

Page 4: Web ui tests examples with  selenide, nselene, selene & capybara

public class TodoMVCTest { @Test public void testFilterTasks(){ Tasks.visit(); Tasks.add("a", "b", "c"); Tasks.shouldBe("a", "b", "c"); Tasks.toggle("b"); Tasks.filterActive (); Tasks.shouldBe("a", "c"); Tasks.filterCompleted (); Tasks.shouldBe("b"); }}

Page 5: Web ui tests examples with  selenide, nselene, selene & capybara

[TestFixture ()] public class Test : BaseTest{ [Test ()] public void FilterTasks () { Tasks.Visit (); Tasks.Add ("a", "b", "c"); Tasks.ShouldBe ("a", "b", "c"); Tasks.Toggle ("b"); Tasks.FilterActive (); Tasks.ShouldBe ("a", "c"); Tasks.FilterCompleted (); Tasks.ShouldBe ("b"); }}

Page 6: Web ui tests examples with  selenide, nselene, selene & capybara

class TestTodoMVC(BaseTest): def test_filter_tasks(self): tasks.visit() tasks.add("a", "b", "c") tasks.should_be("a", "b", "c") tasks.toggle("b") tasks.filter_active () tasks.should_be("a", "c") tasks.filter_completed () tasks.should_be("b")

Page 7: Web ui tests examples with  selenide, nselene, selene & capybara

describe "todomvc" do it "filters tasks" do Tasks.open

Tasks.add "a", "b", "c" Tasks.should_be "a", "b", "c" Tasks.toggle "b" Tasks.filter_active Tasks.should_be "a", "c" Tasks.filter_completed Tasks.should_be "b" endend

Page 8: Web ui tests examples with  selenide, nselene, selene & capybara

Step-Helperssimpler

Page 9: Web ui tests examples with  selenide, nselene, selene & capybara

public class Tasks { ... public static void visit() { open("https://todomvc4tasj.herokuapp.com/"); } public static void filterActive(){ $(By.linkText("Active")).click(); } public static void filterCompleted(){ $(By.linkText("Completed")).click(); } public static void add(String... taskTexts) { for(String text: taskTexts){ $("#new-todo").setValue(text).pressEnter(); } } ...}

Page 10: Web ui tests examples with  selenide, nselene, selene & capybara

public static class Tasks{ ... public static void Visit() { Open ("https://todomvc4tasj.herokuapp.com/"); } public static void FilterActive () { S (By.LinkText ("Active")).Click (); } public static void FilterCompleted () { S (By.LinkText ("Completed")).Click (); } public static void Add(params string[] taskTexts) { foreach (var text in taskTexts) { S ("#new-todo").SetValue (text).PressEnter (); } } ...}

Page 11: Web ui tests examples with  selenide, nselene, selene & capybara

def visit(): tools.visit("https://todomvc4tasj.herokuapp.com/")def filter_active(): s(by_link_text(”Active”)).click()def filter_completed(): s(by_link_text(”Completed”)).click()def add(*task_texts): for text in task_texts: s("#new-todo").set_value(text).press_enter()

Page 12: Web ui tests examples with  selenide, nselene, selene & capybara

module Tasks extend Capybara::DSL def self.open visit 'https://todomvc4tasj.herokuapp.com' end def self.filter_active find("a", text:"Active").click end def self.filter_completed find("a", text:"Completed").click end def self.add *task_texts task_texts.each do |text| find("#new-todo").send_keys(text, :enter) end end ...end

Page 13: Web ui tests examples with  selenide, nselene, selene & capybara

Step-Helpersa bit harder

Page 14: Web ui tests examples with  selenide, nselene, selene & capybara

public class Tasks { public static ElementsCollection tasks = $$("#todo-list>li"); ... public static void toggle(String taskText) { tasks.findBy(exactText(taskText)).find(".toggle").click(); } public static void shouldBe(String... taskTexts) { tasks.filterBy(visible).shouldHave(exactTexts(taskTexts)); }}

Page 15: Web ui tests examples with  selenide, nselene, selene & capybara

public static class Tasks{ public static SCollection List = SS ("#todo-list>li"); ... public static void Toggle (string taskText) { List.FindBy (Have.ExactText(taskText)).Find (".toggle").Click(); } public static void ShouldBe(params string[] names) { List.FilterBy (Be.Visible).Should (Have.Texts (names)); }}

Page 16: Web ui tests examples with  selenide, nselene, selene & capybara

tasks = ss("#todo-list>li")...

def toggle(task_text): tasks.findBy(exact_text(task_text)).find(".toggle").click()def should_be(*task_texts): tasks.filterBy(visible).should_have(exact_texts(*task_texts))

Page 17: Web ui tests examples with  selenide, nselene, selene & capybara

module Tasks extend Capybara::DSL def self.tasks all "#todo-list>li" end ... def self.toggle task_text (tasks.findBy {|task| task.text == task_text}).find(".toggle").click end def self.should_be *task_texts tasks.texts.should == task_texts endend

Page 18: Web ui tests examples with  selenide, nselene, selene & capybara

module Tasks extend Capybara::DSL def self.tasks all "#todo-list>li" end ... def self.toggle task_text (tasks.findBy {|task| task.text == task_text}).find(".toggle").click end def self.should_be *task_texts tasks.texts.should == task_texts endend

is == above ;)==

Page 19: Web ui tests examples with  selenide, nselene, selene & capybara

Easy?

Page 20: Web ui tests examples with  selenide, nselene, selene & capybara

Easy Tools

http://selenide.org

https://github.com/jnicklas/capybara

https://github.com/yashaka/selene

https://github.com/yashaka/NSelene