diff --git a/t/controller_domain_selenium.t b/t/controller_domain_selenium.t index f995ed2040..767b329bc1 100644 --- a/t/controller_domain_selenium.t +++ b/t/controller_domain_selenium.t @@ -4,7 +4,9 @@ use Test::More import => [qw(done_testing is ok)]; use Test::WebDriver::Sipwise qw(); my $d = Test::WebDriver::Sipwise->new; -$d->get_ok($ENV{CATALYST_SERVER} || 'http://localhost:3000'); +my $uri = $ENV{CATALYST_SERVER} || 'http://localhost:3000'; +$d->get_ok("$uri/logout"); #make sure we are logged out +$d->get_ok("$uri/login"); $d->set_implicit_wait_timeout(1000); $d->findtext_ok('Subscriber Sign In'); @@ -14,7 +16,7 @@ $d->find(name => 'username')->send_keys('administrator'); $d->find(name => 'password')->send_keys('administrator'); $d->findclick_ok(name => 'submit'); -$d->text_is('//title', 'Dashboard'); +$d->title_is('Dashboard'); $d->findclick_ok(xpath => '//*[@id="main-nav"]//*[contains(text(),"Settings")]'); $d->find_ok(xpath => '//a[contains(@href,"/domain")]'); @@ -25,10 +27,12 @@ $d->findclick_ok(xpath => "/html/body/div/div[4]/div/div[3]/table/tbody/tr/td/a" $d->location_like(qr!domain/\d+/preferences!); #/ $d->findclick_ok(link_text => "Access Restrictions"); -my $edit_link = $d->find(xpath => '(//table/tbody/tr/td[normalize-space(text()) = "concurrent_max"]/../td//a)[2]'); + +my $row = $d->find(xpath => '//table/tbody/tr/td[normalize-space(text()) = "concurrent_max"]'); +ok($row); +my $edit_link = $d->find_child_element($row, '(./../td//a)[2]'); ok($edit_link); -#workaround to make the button visible -$d->execute_script('$(".sw_actions").removeAttr("style")'); +$d->move_to(element => $row); $edit_link->click; my $formfield = $d->find('id' => 'concurrent_max'); diff --git a/t/controller_reseller_selenium.t b/t/controller_reseller_selenium.t index 9b442a77a5..942aefd69b 100644 --- a/t/controller_reseller_selenium.t +++ b/t/controller_reseller_selenium.t @@ -6,7 +6,9 @@ use Test::WebDriver::Sipwise qw(); #my $sel = Test::WWW::Selenium::Catalyst->start({default_names => 1}); my $d = Test::WebDriver::Sipwise->new; -$d->get_ok($ENV{CATALYST_SERVER} || 'http://localhost:3000'); +my $uri = $ENV{CATALYST_SERVER} || 'http://localhost:3000'; +$d->get_ok("$uri/logout"); #make sure we are logged out +$d->get_ok("$uri/login"); $d->set_implicit_wait_timeout(1000); #$sel->is_text_present_ok('Subscriber Sign In'); @@ -20,7 +22,8 @@ $d->find(name => 'password')->send_keys('administrator'); $d->findclick_ok(name => 'submit'); #$sel->wait_for_page_to_load_ok(2000); -$d->text_is('//title', 'Dashboard'); +#$d->text_is('//title', 'Dashboard'); +$d->title_is('Dashboard'); $d->findclick_ok(xpath => '//a[@class="btn" and @href="/reseller"]'); my $searchfield = $d->find(css => '#Reseller_table_filter label input'); @@ -36,8 +39,6 @@ $searchfield->send_keys('1'); $d->find_ok(css => '#Reseller_table tr.sw_action_row'); is($d->find(css => '#Reseller_table tr:nth-of-type(1) > td:nth-of-type(1)')->get_text,'1'); -#the rest is not yet ported to webdriver: - $d->findclick_ok(link_text => 'Create Reseller'); $d->findclick_ok(id => 'save'); $d->findtext_ok("Contract field is required"); @@ -45,17 +46,23 @@ $d->findtext_ok("Name field is required"); $d->findtext_ok("Status field is required"); $d->findclick_ok(id => 'mod_close'); -#workaround to make the button visible -$d->execute_script('$(".sw_actions").removeAttr("style").delay(500);'); -$d->execute_script('$(".sw_actions").attr("style", "display:block")'); -$d->findclick_ok(xpath => '//*[@id="Reseller_table"]/tbody/tr[1]//a[contains(text(),"Edit")]'); +sleep 1; #prevent a StaleElementReferenceException +my $row = $d->find(xpath => '//*[@id="Reseller_table"]/tbody/tr[1]'); +ok($row); +$d->move_to(element => $row); +my $btn = $d->find_child_element($row, './/a[contains(text(),"Edit")]'); +ok($btn); +$btn->click; is($d->find(id => "name")->get_attribute("value"), "reseller 1"); $d->findclick_ok(id => 'mod_close'); -#same workaround -$d->execute_script('$(".sw_actions").removeAttr("style").delay(500);'); -$d->execute_script('$(".sw_actions").attr("style", "display:block")'); -$d->findclick_ok(xpath => '//*[@id="Reseller_table"]/tbody/tr[1]//a[contains(@class,"btn-secondary")]'); +sleep 1; #prevent a StaleElementReferenceException +$row = $d->find(xpath => '//*[@id="Reseller_table"]/tbody/tr[1]'); +ok($row); +$d->move_to(element => $row); +$btn = $d->find_child_element($row, './/a[contains(@class,"btn-secondary")]'); +ok($btn); +$btn->click; $d->findtext_ok("Are you sure?"); $d->findclick_ok(xpath => '//div[@id="dataConfirmModal"]//a[contains(text(),"Delete")]'); is($d->find(css => 'div.alert-info')->get_text, 'Reseller delete not implemented!'); diff --git a/t/lib/Test/WebDriver/Sipwise.pm b/t/lib/Test/WebDriver/Sipwise.pm index f5655d486d..b9717bfb6e 100644 --- a/t/lib/Test/WebDriver/Sipwise.pm +++ b/t/lib/Test/WebDriver/Sipwise.pm @@ -16,3 +16,13 @@ method findclick(Str $scheme, Str $query) { method findtext(Str $text, Any $ignore) { return $self->find(xpath => "//*[contains(text(),\"$text\")]"); } + +method save_screenshot() { + use MIME::Base64; + local *FH; + open(FH,'>','screenshot.png'); + binmode FH; + my $png_base64 = $self->screenshot(); + print FH decode_base64($png_base64); + close FH; +}