[LON-CAPA-cvs] cvs: modules /goltermann/internalTest/t InterfaceTest.pm ProblemTest.pm

goltermann goltermann at source.lon-capa.org
Thu Jun 20 06:42:19 EDT 2013


goltermann		Thu Jun 20 10:42:19 2013 EDT

  Modified files:              
    /modules/goltermann/internalTest/t	InterfaceTest.pm ProblemTest.pm 
  Log:
  added missing files
  
  
  
Index: modules/goltermann/internalTest/t/InterfaceTest.pm
diff -u /dev/null modules/goltermann/internalTest/t/InterfaceTest.pm:1.3
--- /dev/null	Thu Jun 20 10:42:19 2013
+++ modules/goltermann/internalTest/t/InterfaceTest.pm	Thu Jun 20 10:42:18 2013
@@ -0,0 +1,55 @@
+#!perl
+use strict;
+use warnings;
+package InterfaceTest;
+use Test::More;
+use Test::WWW::Selenium;
+
+
+my $maxTimeout = 30000;
+my $sel;
+
+
+# for now this only sends a internal msg to yourself and checks if this arrived
+sub run(){
+    shift; # _important_ to have the right hash to work with
+    my %config = @_;
+
+    &Util::login(%config);
+    &sendmessage(%config);
+}
+
+# send and recieve of internal messages
+sub sendmessage{
+
+    $sel = Util::getActiveBrowser();
+    my %config = @_;
+    my $user = $config{'user'};
+
+    my $address = $sel->{'browser_url'};        # url stem from selenium instance
+    my $timestamp = localtime;
+    my $uniqueText = 'Dies ist eine Testnachricht.';
+
+    # send a mail
+    $sel->open($address.'adm/email?compose=individual');
+    $sel->wait_for_page_to_load($maxTimeout);
+    $sel->type('recuname', $user);
+    $sel->type('subject', $timestamp);
+    $sel->type('message', $uniqueText);
+    &Util::takeScreenshot('send mail interface');
+    $sel->click_ok('send', undef, 'mail sent');
+    $sel->pause(2000);
+
+    # check for new mail and get value
+    ok($sel->get_html_source() =~ m/<a href="\/adm\/email\?display=(.*?)&.*?>$timestamp/i, 'mail recieved');
+
+    my $clickme = $1;
+    &Util::takeScreenshot('recieved mails');
+
+    # delete mail with saved value
+    $sel->click_ok("name=delmark value=$clickme", undef, 'checkbox for mail set');
+    $sel->click_ok("name=go", undef, 'mail deleted');
+    $sel->wait_for_page_to_load($maxTimeout);
+    $sel->pause(5000);
+}
+1;
Index: modules/goltermann/internalTest/t/ProblemTest.pm
diff -u /dev/null modules/goltermann/internalTest/t/ProblemTest.pm:1.3
--- /dev/null	Thu Jun 20 10:42:19 2013
+++ modules/goltermann/internalTest/t/ProblemTest.pm	Thu Jun 20 10:42:18 2013
@@ -0,0 +1,181 @@
+#!perl
+use strict;
+use warnings;
+package ProblemTest;
+use Test::More;
+use Test::WWW::Selenium;
+# use Smart::Comments;
+
+my $problemname = 'uniqueTestProb.problem';
+my $maxTimeout = 30000;
+my $oldConstrSpace = 1;              #set this if you use the old construction space (<version_2_11_X)
+
+my $sel;
+my %config;
+my $user;
+my $pass;
+my $dom;
+
+# runs all tests
+sub run(){
+    shift; # get rid of foreign package name, _important_ to have the right hash to work with
+    %config = @_;
+
+    $sel = Util::getActiveBrowser();
+
+    # makes code easier to read and tidier
+    $user = $config{'user'};
+    $pass = $config{'pw'};
+    $dom = $config{'domain'};
+
+    # start your test functions here:
+    &testLogins();
+    &createProblem();
+
+    SKIP: {
+        skip "This test might fail because LONCAPA times out randomly", 2;
+        &testMaxima();
+    };
+
+    &cleanup();
+}
+
+sub testLogins(){
+
+    &badLogin();
+
+    &Util::login(%config);
+    ok($sel->get_html_source() !~ /href="\/adm\/loginproblems.html"/, 'Login');
+}
+
+# Creates an empty problem
+# Contains 3 tests
+sub createProblem(){
+
+# check if previous login was ok
+
+    $sel->open('/adm/roles');
+    $sel->wait_for_page_to_load($maxTimeout);
+    &Util::takeScreenshot('available roles');
+    $sel->click("//input[\@name='au".$dom."']", undef, 'rolechoice author');
+    $sel->wait_for_page_to_load($maxTimeout);
+
+    if($oldConstrSpace){
+        $sel->open("/priv/$user/");
+    }else{
+        $sel->open("/priv/$dom/$user/");
+    }
+    $sel->wait_for_page_to_load($maxTimeout);
+    &Util::takeScreenshot('construction space');
+    $sel->select('css=select[name="action"]', 'value=newproblemfile');
+    $sel->type('name=newfilename', $problemname);
+
+    # Test1: create .problem file:
+    $sel->click_ok('//span/input[3]', undef, 'creating problem file');
+    $sel->wait_for_page_to_load($maxTimeout);
+    &Util::takeScreenshot('problem file creation');
+
+    # Test 2: confirm problem creation
+    if($sel->get_html_source() =~ m/LC_warning/){
+        # if test problem already exists
+        # print "Bail out! $problemname already exists. cancel to prevent data loss." unless $override;
+        $sel->click_ok('css=input[type="submit"]', undef, "$problemname overwritten");
+    }else{
+        # else select blank template
+        $sel->click('css=input[type="submit"]');
+        $sel->wait_for_page_to_load($maxTimeout);
+
+        $sel->check("//input[\@value='/home/httpd/html/res/adm/includes/templates/blank.problem']");
+        $sel->click_ok('name=newfile', undef, 'chose blank problem template');
+    }
+
+    # $sel->wait_for_page_to_load($maxTimeout);
+}
+
+# Inserts the XML of a maxima problem
+# Contains 2 tests
+sub testMaxima(){
+
+    return if $config{'fast'};
+    my $maxproblemxml = &Util::getProblemXML_Maxima();
+
+    # open problem in editor [Test 1]
+    if($oldConstrSpace){
+        $sel->open_ok("/priv/$user/$problemname?forceedit=1", undef, 'open XML editor');
+    }else{
+        $sel->open_ok("/priv/$dom/$user/$problemname?editmode=Edit&problemmode=editxml", undef, 'open XML editor');
+    }
+    $sel->wait_for_page_to_load($maxTimeout);
+
+    # Paste problem xml
+    $sel->type('name=editxmltext',$maxproblemxml);
+    &Util::takeScreenshot('xml editor');
+
+    # [Test 2] finish creating problem
+    $sel->click('name=subsaveview');
+    $sel->wait_for_page_to_load($maxTimeout);
+    # ok if no error message
+    &Util::takeScreenshot('finish problem creation');
+    unlike($sel->get_html_source(), qr/<span class="LC_error">/, 'create problem');
+
+    # calculate 20 answers, this may take a while
+    $sel->click('//div[3]/span/input');
+    $sel->pause(1000);
+
+    # waiting time per problem * nr problem * 1000ms:
+    $sel->wait_for_page_to_load(2.5*20*1000); #~2.5sec per answer should be fine. if there is a timeout it takes 10sec per timed out answer
+}
+
+# Deletes the created problem
+# Contains 1 test
+sub cleanup(){
+
+    if($oldConstrSpace){
+        $sel->open("/priv/$user/$problemname");
+    }else{
+        $sel->open("/priv/$dom/$user/$problemname");
+    }
+    $sel->wait_for_page_to_load($maxTimeout);
+
+    # clicking the delete button
+    if($oldConstrSpace){
+        $sel->click('//li[4]/a/span');
+    }else{
+        $sel->click('//ul/li[4]/a/span');
+    }
+    $sel->wait_for_page_to_load($maxTimeout);
+
+    # now delete problem
+    $sel->click_ok("css=input[type='submit']", undef, 'cleanup done');
+    $sel->wait_for_page_to_load($maxTimeout);
+}
+
+# Login with bad pw
+# Contains 2 tests
+sub badLogin(){
+    return if $config{'fast'};
+    # page opens
+    &Util::logout();
+    $sel->open_ok('/adm/roles', undef, 'login page online');
+    $sel->wait_for_page_to_load($maxTimeout);
+    $sel->pause(1000);    # stabalize safari
+    $sel->type('id=uname', $user);
+
+    # alles kaka, einfach timestamp oder so verwenden
+    # my $wrongpw = '§wo at 1g3_f5z??w"i#f'; # wrong password
+    # # making sure that this is not an actual password...
+    # if ($pass ne $wrongpw) {
+    #     $sel->type('//div[2]/div/form/input[4]', $wrongpw);
+    # }else{
+    #     $sel->type('//div[2]/div/form/input[4]', 'somethingdifferent');
+    # }
+    my $wrongpw = localtime; # this is a wrong password
+    $sel->submit('name=client');
+    $sel->wait_for_page_to_load($maxTimeout);
+    # ok if no link to loginproblems help page
+    ok($sel->get_html_source() =~ /href="\/adm\/loginproblems.html"/, 'bad password rejected');
+    &Util::takeScreenshot('login failed');
+}
+
+
+1;




More information about the LON-CAPA-cvs mailing list