diff --git a/test-data/selenium-test-notebook.ipynb b/test-data/selenium-test-notebook.ipynb new file mode 100644 index 00000000000..1cdb2736403 --- /dev/null +++ b/test-data/selenium-test-notebook.ipynb @@ -0,0 +1,152 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "deletable": true, + "editable": true + }, + "source": [ + "# Welcome to the interactive Galaxy IPython Notebook." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": true, + "editable": true + }, + "source": [ + "You can access your data via the dataset number. For example, ``handle = open(get(42), 'r')``.\n", + "To save data, write your data to a file, and then call ``put('filename.txt')``. The dataset will then be available in your galaxy history.\n", + "Notebooks can be saved to Galaxy by clicking the large green button at the top right of the IPython interface.
\n", + "More help and informations can be found on the project [website](https://github.com/bgruening/galaxy-ipython)." + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false, + "deletable": true, + "editable": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'/import/1'" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "get(1)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "chr6_hla_hap2 0 150\r\n" + ] + } + ], + "source": [ + "!grep chr6 /import/1" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "!echo \"Hello World\" > /tmp/cow" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "put(\"/tmp/cow\")" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1 [2] 1.txt.gg ipython_galaxy_notebook.ipynb\r\n" + ] + } + ], + "source": [ + "!ls /import" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "put(\"/import/ipython_galaxy_notebook.ipynb\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.12" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/test/galaxy_selenium/navigates_galaxy.py b/test/galaxy_selenium/navigates_galaxy.py index e7b39eb378e..fc6e9cb37bd 100644 --- a/test/galaxy_selenium/navigates_galaxy.py +++ b/test/galaxy_selenium/navigates_galaxy.py @@ -46,6 +46,8 @@ WAIT_TYPES = Bunch( DATABASE_OPERATION=WaitType("database_operation", 10), # Wait time for jobs to complete in default environment. JOB_COMPLETION=WaitType("job_completion", 30), + # Wait time for a GIE to spawn. + GIE_SPAWN=WaitType("gie_spawn", 30), ) # Choose a moderate wait type for operations that don't specify a type. @@ -806,6 +808,30 @@ class NavigatesGalaxy(HasDriver): action_element = menu_element.find_element_by_link_text(action) action_element.click() + def history_panel_item_click_visualization_menu(self, hid): + viz_button_selector = "%s %s" % (self.history_panel_item_selector(hid), ".visualizations-dropdown") + self.wait_for_and_click_selector(viz_button_selector) + self.wait_for_selector_visible("%s %s" % (viz_button_selector, ".dropdown-menu")) + + def history_panel_item_available_visualizations_elements(self, hid): + # Precondition: viz menu has been opened with history_panel_item_click_visualization_menu + viz_menu_selectors = "%s %s" % (self.history_panel_item_selector(hid), "a.visualization-link") + return self.driver.find_elements_by_css_selector(viz_menu_selectors) + + def history_panel_item_available_visualizations(self, hid): + # Precondition: viz menu has been opened with history_panel_item_click_visualization_menu + return [e.text for e in self.history_panel_item_available_visualizations_elements(hid)] + + def history_panel_item_click_visualization(self, hid, visualization_name): + # Precondition: viz menu has been opened with history_panel_item_click_visualization_menu + elements = self.history_panel_item_available_visualizations_elements(hid) + for element in elements: + if element.text == visualization_name: + element.click() + return element + + assert False, "No visualization [%s] found." % visualization_name + def history_panel_item_selector(self, hid, wait=False): current_history_id = self.current_history_id() contents = self.api_get("histories/%s/contents" % current_history_id) diff --git a/test/selenium_tests/framework.py b/test/selenium_tests/framework.py index 3cc9a5f35b3..fb7f93de271 100644 --- a/test/selenium_tests/framework.py +++ b/test/selenium_tests/framework.py @@ -279,6 +279,15 @@ class SeleniumTestCase(FunctionalTestCase, NavigatesGalaxy): def workflow_populator(self): return SeleniumSessionWorkflowPopulator(self) + def ensure_visualization_available(self, hid, visualization_name): + """Skip or fail a test if visualization for file doesn't appear. + + Precondition: viz menu has been opened with history_panel_item_click_visualization_menu. + """ + visualization_names = self.history_panel_item_available_visualizations(hid) + if visualization_name not in visualization_names: + raise unittest.SkipTest("Skipping test, visualization [%s] doesn't appear to be configured." % visualization_name) + class SharedStateSeleniumTestCase(SeleniumTestCase): """This describes a class Selenium tests that setup class state for all tests. diff --git a/test/selenium_tests/test_jupyter.py b/test/selenium_tests/test_jupyter.py new file mode 100644 index 00000000000..4d46a3dbef8 --- /dev/null +++ b/test/selenium_tests/test_jupyter.py @@ -0,0 +1,46 @@ +from .framework import ( + managed_history, + selenium_test, + SeleniumTestCase, +) + +JUPYTER_VISUALIZATION_NAME = "Jupyter" + + +class JupyterTestCase(SeleniumTestCase): + + ensure_registered = True + + @selenium_test + @managed_history + def test_jupyter_session(self): + self.perform_upload(self.get_filename("1.txt")) + self.perform_upload(self.get_filename("selenium-test-notebook.ipynb")) + self.wait_for_history() + self.history_panel_ensure_showing_item_details(2) + self.history_panel_item_click_visualization_menu(2) + self.ensure_visualization_available(2, JUPYTER_VISUALIZATION_NAME) + self.history_panel_item_click_visualization(2, JUPYTER_VISUALIZATION_NAME) + with self.main_panel(): + viz_iframe = self.wait_for_selector("body iframe", wait_type=self.wait_types.GIE_SPAWN) + try: + self.driver.switch_to.frame(viz_iframe) + self.wait_for_selector("ul.nav") + lis = self.driver.find_elements_by_css_selector("ul.nav li.dropdown") + cell_li = None + for li in lis: + if li.text == "Cell": + cell_li = li + break + cell_li.click() + self.wait_for_and_click_selector("ul#cell_menu li#run_all_cells") + finally: + self.driver.switch_to.default_content() + + # TODO: wait on something in the notebook instead of sleeping so long. + self.sleep_for(wait_type=self.wait_types.JOB_COMPLETION) + self.history_panel_refresh_click() + + # Re-running notebook should publish two new things to the history. + self.history_panel_wait_for_hid_ok(3) + self.history_panel_wait_for_hid_ok(4)