ref: refs/heads/master
commit 4070181f4b31d9046a2ae8becb9c336fde336441
Author: Ladislav Slezak
Date: Tue Jul 21 09:26:58 2009 +0200
Added custom output formatter for Selenium IDE
This formatter extends the standard Ruby output formatter (ruby-rc.js)
Extensions:
- exports tests using WebYaST Selenium::TestCase base class
(the common parts are shared in the base class)
- can export also whole testsuite
- Selenium script can contain inline Ruby code (comments starting with "@RUBY:" string,
unfortunately it works only in test suite export, not in single test case export)
Use 'Options->Options...->Formats->Add' menu item in Selenium IDE for loading the file.
---
webclient/test/ui/README | 11 ++++
webclient/test/ui/ruby-webyast.js | 105 +++++++++++++++++++++++++++++++++++++
2 files changed, 116 insertions(+), 0 deletions(-)
diff --git a/webclient/test/ui/README b/webclient/test/ui/README
new file mode 100644
index 0000000..0e7e216
--- /dev/null
+++ b/webclient/test/ui/README
@@ -0,0 +1,11 @@
+Here are UI testing scripts using Selenium framework (http://seleniumhq.org)
+
+Basic information:
+
+1. run 'rake test:ui' to start UI tests
+2. the tests have been generated from *.xml files by Selenium IDE
+ (do not edit them directly, use Selenium IDE for changes and export the tests)
+
+See http://en.opensuse.org/YaST/Web/Development/UI_Testing for more information.
+
+
diff --git a/webclient/test/ui/ruby-webyast.js b/webclient/test/ui/ruby-webyast.js
new file mode 100644
index 0000000..9b5fb41
--- /dev/null
+++ b/webclient/test/ui/ruby-webyast.js
@@ -0,0 +1,105 @@
+/*
+ * This is a custom output formatter for Selenium IDE
+ *
+ * Use 'Options->Options...->Formats->Add' menu item in Selenium IDE for loading the file.
+ *
+ * This formatter extends the standard Ruby formatter (ruby-rc.js)
+ *
+ * Extensions:
+ * - exports tests using WebYaST Selenium::TestCase base class
+ * (the common parts are shared in the base class)
+ * - can export also whole testsuite
+ * - Selenium script can contain inline Ruby code (comments starting with "@RUBY:" string,
+ * unfortunately it works only in test suite export, not in single test case export)
+ */
+
+// preload the standard Ruby RC output formatter
+load('ruby-rc.js');
+
+this.name = "ruby-webyast";
+this.plugin_version = "0.1";
+
+this.options = {
+ receiver: "@selenium",
+ header:
+ '# Generated by ' + this.name + '-' + this.plugin_version + ' Selenium formatter\n' +
+ '# Date: ' + Date() + '\n\n' +
+ 'require "selenium/test_case"\n' +
+ '\n' +
+ 'class ${className} < Selenium::TestCase\n' +
+ ' \n' +
+ ' def ${methodName}\n',
+ footer:
+ " end\n" +
+ "end\n",
+ indent: "2",
+ initialIndents: "2"
+};
+
+this.configForm =
+ '<description>Variable for Selenium instance</description>' +
+ '<textbox id="options_receiver" />' +
+ '<description>Indent</description>' +
+ '<menulist id="options_indent"><menupopup>' +
+ '<menuitem label="Tab" value="tab"/>' +
+ '<menuitem label="1 space" value="1"/>' +
+ '<menuitem label="2 spaces" value="2"/>' +
+ '<menuitem label="3 spaces" value="3"/>' +
+ '<menuitem label="4 spaces" value="4"/>' +
+ '<menuitem label="5 spaces" value="5"/>' +
+ '<menuitem label="6 spaces" value="6"/>' +
+ '<menuitem label="7 spaces" value="7"/>' +
+ '<menuitem label="8 spaces" value="8"/>' +
+ '</menupopup></menulist>';
+
+/**
+ * Returns a string representing the test suite for Ruby language (in WebYaST format).
+ *
+ * @param testSuite the suite to format
+ * @param filename the file the formatted suite will be saved as
+ */
+function formatSuite(testSuite, filename) {
+ var suiteClass = /^(\w+)/.exec(filename)[1];
+ suiteClass = suiteClass[0].toUpperCase() + suiteClass.substring(1);
+ suiteClass = suiteClass.replace(/ /g, '_');
+
+ // header
+ var formattedSuite =
+ '# Generated by ' + this.name + '-' + this.plugin_version + ' Selenium formatter\n' +
+ '# Date: ' + Date() + '\n\n' +
+ 'require "selenium/test_case"\n\n' +
+ 'class ' + suiteClass + ' < Selenium::TestCase\n';
+
+ // backup the standard options
+ var opts_bak = this.options;
+
+ // change the options temporarily
+ this.options = {
+ receiver: "@selenium",
+ header: ' \n' +
+ ' def ${methodName}\n',
+ footer: ' end\n\n',
+ indent: "2",
+ initialIndents: "2"
+ };
+
+ // export each testcase using the temporary options
+ for (var i = 0; i < testSuite.tests.length; ++i) {
+ var formattedTest = format(testSuite.tests[i].content);
+ // uncomment inline Ruby commands
+ formattedTest = formattedTest.replace(/^([ \t]*)#[ \t]*@RUBY:[ \t]*(.*)$/mg, '$1$2');
+
+ formattedSuite += formattedTest;
+ }
+
+ // footer
+ formattedSuite += "\nend\n";
+
+ // restore the standard options
+ this.options = opts_bak;
+
+ this.log.info('Generated testsuite: ' + filename);
+
+ return formattedSuite;
+}
+
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org