refactoror / SelBlocks

SelBlocks extension for Selenium IDE
10 stars 7 forks source link

Create user-extensions.js #13

Closed matthewkastor closed 9 years ago

matthewkastor commented 9 years ago

Concatenates all the files from the extensions folder in the same order as is listed in extension-loader.xul. Adds testCase as a global var. changes all testCase.debugContext to just testCase. Fixes nextCommand so it will work on the server. Fixes setNextCommand to work on the server. Adds mapList for importing the collection of commands onto testCase. Fixes $$.fn.interceptAfter(Selenium.prototype, "reset", function to set up testCase on the server. Extends HtmlRunnerTestLoop.prototype.initialize to set up testCase.

I've tested this file on FireFox 34.0.5 a little bit. It appears to allow me to use functions and if statements in Selenese scripts. I haven't tried anything else, and what I did try was as simple as possible.

matthewkastor commented 9 years ago

There's a copy of the bat file I use to launch the standalone server with this user-extensions.js file. https://gist.github.com/matthewkastor/89d6eb7ca4ef08b835de

refactoror commented 9 years ago

Matthew, thanks for doing this. It looks like your proposed changes are present only in userextension.js, but I can't make much use of it because it has been reformatted, and therefore cannot be compared directly with selblocks.js. Can you provide the changes without any reformatting?

Also, I am not using Selenium Server, and so I would be dependent on your testing, which would need to be thorough. The best way to accomplish that would be to run the full SelBlock test suite in the server. Note that the test suite requires the SelBench addon, which would therefore need to be incorporated into the userextension.js as well.

matthewkastor commented 9 years ago

I used the "jstool" plugin in notepad++ to format the code and the "compare" plugin to find the differences. There's a "jslint" plugin as well. XD It makes writing JavaScript a lot easier. All it's missing is intellisense XD.

I started with the server extension built against version 1.3, concatenated all the code from the current Firefox extension into another file, and formatted both files. Then I rearranged things in the old server extension so they would line up with the concatenated file. After that, it was basically just using the compare tool to manually merge the two files. I kept all the code from the current extension and only pulled in the old file's augmentation of the server environment. That almost worked, but the method for getting the next command wasn't working. I looked at the method in the server and IDE and figured out how to make it actually get the next command.

I didn't make the changes to the Firefox extension because the changes are just trying to mimic what the IDE does to the environment. If I make the Firefox extension match the server extension it will probably break. I could run the formatter against the extension code and run the tests, then check in those changes if everything passes. It would make diffing the files a lot easier.

I'm not back to work until after the new year holiday so I've got time to try doing some cool stuff. XD I'll see if I can get the tests running on the server, but if they're using any Mozilla stuff like "components.classes" I might not be able to do it. First, I need to eat some lunch. Then I'll get to the cafe and let the coffee write some code XD

refactoror commented 9 years ago

The only way I could incorporate this would be to make the final code smart enough to detect/support each environment, (i.e., not duplicate code), and always derive userextension.js from that..

matthewkastor commented 9 years ago

I think the test would be whether or not testCase exists. If it does then the extension world as is. If it doesn't, then the extra code needs to be executed. XD

I'm working on getting the tests in order against the current dev ff extension. Then I'll see about getting them to run on the server against this.

refactoror commented 9 years ago

Matthew, it occurs to me that you are working with essentially year-old code, so I have pushed 2.0.2. (See build/createSelblocksXpi.bat if you need the .xpi file for installing.) Please submit future pull requests without doing any reformatting. thanks,

matthewkastor commented 9 years ago

I had to do the reformat so I could make sense of merging things. Don't worry, one I get selbench running on the server I'll come back to this and work with the current code from this repo. I'll try to work in the logic for determining whether we're on the server or not. You know, something simple that you could just add to your build batch file. XD

refactoror commented 9 years ago

I'm not sure of the details, but I'm thinking that the server-specific stuff could go into its own .js file, say in the build directory, for cat'g into userextension.js. Same for SelBench, such that both could be combined when necessary.

matthewkastor commented 9 years ago

XD check out the new pull request. It's amazing. XD

refactoror commented 9 years ago

Yep, this is getting nicely cohesive. Questions:

Also, the selblocks object, (defined in name-space.js), is intended as the globalContext. You can just add to it: selblocks.testCase = {}

matthewkastor commented 9 years ago

I'm on my way to the cafe. I've made a little progress, the interception for selenium reset... my guard clause is only allowing the augmentation to run on the first call to reset. I'm going to pull the server code out into it's own file, but I'll have to intercept the reset before any other extensions do. This will take a minute to get right.

The anonymous functions you've got, encapsulate the variables and functions defined inside them. You've got it set up to define a namespace, then pass that namespace in and reference it with $$. Assigning to either the selblocks or the $$ will just add to that same namespace. testCase is global though, I wouldn't want to end up with selblocks and selbench having two different ideas of the test case. Things would definitely get weird.

I'm about to fix all of that XD. Then I'll just have to figure out where interceptFrame.attrs.manageError is defined. (Handle as try block : line 43) I looked a little but I'm thirsty. XD

matthewkastor commented 9 years ago

I'm just trying to shim the server so selblocks works, without breaking it as a Firefox extension. You know a lot more about the mechanics here than I do. It does look like it's all about currentTest to me, but there's a lot of augmentation to the selenium-core in the IDE.

I don't know how the run timestamp is used, I just saw it being set and put it in so it would be there. I was worried that it was for benchmarking the runtime of tests or test steps and didn't want it missing.

I think the current row starts null and can end up being undefined as well. Especially since there are stacks of stacks and all kinds of flow control mechanisms. I don't know yet though, I thought you had all of that figured out XD On Dec 20, 2014 3:08 PM, "Matthew Kastor" matthewkastor@gmail.com wrote:

I'm on my way to the cafe. I've made a little progress, the interception for selenium reset... my guard clause is only allowing the augmentation to run on the first call to reset. I'm going to pull the server code out into it's own file, but I'll have to intercept the reset before any other extensions do. This will take a minute to get right.

The anonymous functions you've got, encapsulate the variables and functions defined inside them. You've got it set up to define a namespace, then pass that namespace in and reference it with $$. Assigning to either the selblocks or the $$ will just add to that same namespace. testCase is global though, I wouldn't want to end up with selblocks and selbench having two different ideas of the test case. Things would definitely get weird.

I'm about to fix all of that XD. Then I'll just have to figure out where interceptFrame.attrs.manageError is defined. (Handle as try block : line 43) I looked a little but I'm thirsty. XD

refactoror commented 9 years ago

Okay good, I was not thinking about the selblocks/selbench interaction.

refactoror commented 9 years ago

Just an FYI - I plan to fix the Selbench expectError status setting bug on Tuesday. As I mentioned, this is probably related to the pre-2.0.2 bug try/catch https://github.com/refactoror/SelBlocks/issues/11.

matthewkastor commented 9 years ago

Awesome XD I'm on my way to the cafe now. I've almost got a server debug launcher figured out.

Something came to mind the other day that I haven't looked into yet. All the methods for manipulating the stack are private to the firefox extensions. I'm not sure if the altered stack is as well, with references passed to the various selenium methods. The idea I'm having is that selblocks and selbench might have different ideas about the stack state and model. That's why I'm trying to set up a good launcher, so the test suite will be loaded along with the server extension, and I can use firebug to debug things.

I don't know how to use firebug to debug firefox extensions, but I'd like to. That way I could have a look at the two environments to draw comparisons. This will all take awhile. I've been dusting off my batch scripting hat and having flashbacks of green text and migraines XD On Dec 22, 2014 4:50 PM, "refactoror" notifications@github.com wrote:

Just an FYI - I plan to fix the expectError status setting bug on Tuesday. As I mentioned, this is probably related to the pre-2.0.2 bug try/catch

11 https://github.com/refactoror/SelBlocks/issues/11.

— Reply to this email directly or view it on GitHub https://github.com/refactoror/SelBlocks/pull/13#issuecomment-67894525.

refactoror commented 9 years ago

I use Firebug frequently, but not for Selenium development. I have seen the description for setting that up, and have just never gotten desperate enough to do it. If I recall correctly, it involves setting up a separate Firefox user profile. And yes, bat scripting is often an exercise in futility.

Which kind of stack are you referring to? Selblocks has its block & function stacks, but Selbench doesn't have/need anything like that.

If you mean Javascript stack and state, then Selblocks & Selbench are simultaneously/co-equally participating in Selenium's state. If you setup debugging of Selenium IDE, then you will also be debugging any and all extensions that are loaded.

refactoror commented 9 years ago

BTW, I've begun running Selenium Server to have a look see for myself. It seems to start up okay, but the TestRunner buttons in the browser don't seem to do anything. This is without your server-side modifications for starters, but I was expecting some kind of errors as you originally reported. Am I missing something here? My launcher looks like this:

"%JAVA_HOME%\bin\java" -jar "C:\bin\selenium-server-standalone-2.44.0.jar" ^
    -userExtensions selblocks\SelBlocks\user-extensions.js ^
    -htmlSuite "*firefox C:\Program Files (x86)\Mozilla Firefox\firefox.exe" ^
    "http://htmlpreview.github.io/?https://github.com/refactoror/SelBlocks/blob/master/sel-blocksTests/_SelBlocks-testpage.html" ^
    selblocks\SelBlocks\sel-blocksTests\_SelBlocks-TestSuite.html ^
    selblocks\SelBlocks\sel-blocksTests\_results.html
matthewkastor commented 9 years ago

I was getting confused and thinking there were stacks set up in both extensions. I never really looked at SelBench's code too deeply because it didn't take a lot to make it work on the server. The part I'm having trouble with is getting SelBlocks to behave. XD

For the launcher, I'm not sure why the test runner buttons would be disabled in your browser. When you run the server with the -htmlSuite option it sets the TestRunner to run the full suite automatically, then close when it's finished. For the firefox, you shouldn't have to specify the path to it if that's really where it is on your machine. You could try using full paths to everything, but if the server starts and loads your test suite then everything about your launcher is probably ok. Can you see your test suite load up automatically and try to start running? If it doesn't load you could wrap your paths in quotes and start them with %~dp0 to get the full path to your bat file.

ooh wait. . . I couldn't even get selenium server 2.44.0 to launch Firefox. I think it worked with the internet explorer and chrome if I used the piiexplore or googlechrome and had the drivers in the same folder as selenium. I'm using selenium-server-standalone-2.43.1, IEDriverServer_W32_2.43.0, chromedriver_win32 version 2.13, and it's working on all three browsers.

http://selenium-release.storage.googleapis.com/index.html?path=2.43/ http://chromedriver.storage.googleapis.com/index.html?path=2.13/

There's nothing really to set up if you have the browsers installed in their default path. I'm pretty sure running the internet explorer with the server's proxy injection mode (piiexplore) gets around having to do any weird registry tweaks for ie. I'd already done the "required setup" from the wiki though... except the driver isn't in my path. https://code.google.com/p/selenium/wiki/ChromeDriver https://code.google.com/p/selenium/wiki/InternetExplorerDriver

This is the directory structure I'm working with for both projects and the server:

C:\
   \---projects.
        \---selenium
            +---selbench
            |   \---SelBench
~~~~~~~~~ ~~~~~~~~~ ~~~~~~~~~ ~~~~~~~~~ ~~~~~~~~~
            |       +---testUserExtension
            |       \---user extension
            |           \---scripts
            +---selblocks
            |   \---SelBlocks
~~~~~~~~~ ~~~~~~~~~ ~~~~~~~~~ ~~~~~~~~~ ~~~~~~~~~
            |       +---testUserExtension
            |       \---user extension
            |           \---scripts
~~~~~~~~~ ~~~~~~~~~ ~~~~~~~~~ ~~~~~~~~~ ~~~~~~~~~
            \---server
                    chromedriver.exe
                    IEDriverServer.exe
                    selenium-server-standalone-2.43.1.jar

If you grab the user extensions branch for selbench, it has a copy of my launcher in it. It should work if you put the server in the same relative position to the project. Just run the file runTestsOnServer.cmd start-debug or runTestsOnServer.cmd -help from the testUserExtension directory.

There's this too, I took your launcher and edited it a little, something super simple to experiment with. I'm pretty sure it's the latest server that's giving you trouble though.

SET seleniumServerLocation=C:\bin
SET seleniumServerJar=%seleniumServerLocation%\selenium-server-standalone-2.44.0.jar
SET port=4444
SET testUserExtensions=%~dp0\selblocks\SelBlocks\user-extensions.js
SET serverLog=%~dp0\selblocks\SelBlocks\sel-blocksTests\Server Log.txt
SET browser=firefox
SET baseURL=http://localhost:%port%
SET testSuiteFile=%~dp0\selblocks\SelBlocks\sel-blocksTests\_SelBlocks-TestSuite.html
SET resultsLog=%~dp0\selblocks\SelBlocks\sel-blocksTests\_results
SET autotestTimeoutInSeconds=30

  REM runs test suite specified by testSuiteFile, in the given browser
  start /wait "selenium server" /MIN java -jar "%seleniumServerJar%" ^
 -port %port% ^
 -Dwebdriver.ie.driver="%seleniumServerLocation%\IEDriverServer.exe" ^
 -Dwebdriver.chrome.driver="%seleniumServerLocation%\chromedriver.exe" ^
 -userExtensions "%testUserExtensions%" ^
 -log "%serverLog%" -browserSideLog ^
 -debug ^
 -htmlSuite "*%browser%" "%baseURL%" "%testSuiteFile%" "%resultsLog%-%browser%.html" ^
 -timeout %autotestTimeoutInSeconds%
refactoror commented 9 years ago

Okay, I'll try out 2.43.1.

Also, in case I haven't mentioned before, since Selenium IDE is a Firefox-only extension, SelBlocks code has never been tested in browsers other than Firefox. In particular, I know that the XPath processing is fairly hopeless in IE, and so forxml would be a pain point.

refactoror commented 9 years ago

Also, I really appreciate all your help, Matthew. Yours is the first real coding collaboration since I first started SelBlocks, and you're making me think about stuff that otherwise goes unscrutinized.

matthewkastor commented 9 years ago

XD thank you XD you're doing really great things yourself XD

Xpath is always a pain no matter what. I've been able to use it successfully in IE though. I think one of the main problems was that collections were indexed beginning at zero or one, depending on whether you were in IE or a browser that worked XD they had another feature for preserving whitespace that would upset people as well, but I think it was the xpath function "normalize-space" that would clean up the target and make things work out ok. Besides, who selects elements by index XD xpath let's you pick absolutely anything you want to identify about the elements.

IE 11 is way better as long as quirks mode isn't on. You can disable it so pages that forget doctypes don't automatically throw you back to IE8 XD

I'm sure most things will work, maybe a shim here and there for new experimental awesomeness. . . You're not going crazy and using "let", "Proxy", or "Iterator" are you? There are some things that just don't work with shims, I don't remember seeing any of that though. XD

refactoror commented 9 years ago

Well it has actually been a few years since my IE/XPath experience - circa maybe version 9. So things maybe, hopefully, have improved. SelBlocks itself does not specify any XPath. It provides the $x() and $X() functions for use in sripting, so it's actually at the mercy of whatever the scripter does.

matthewkastor commented 9 years ago

XD http://matthewkastor.github.io/AtropaToolbox-raw-js/docs/jsdoc/symbols/atropa.xpath.html

I always used it in Firefox but I've got good tests. It's the only thing missing from browsers that can parse xpath. I should test it on IE 11 when I get a minute XD

DavidSoussan commented 7 years ago

I tried this out using your user-extension.js in the IDE and get an immediate error

There was an unexpected error. Msg: TypeError: this._advanceToNextRow is not a function Url: chrome://selenium-ide/content/tools.js -> file:///L:/integro/deploy/tests/SeleniumIDE/000.UserExtensions/selblocks.js?1499335510613, line: 598, column: 17 nextCommand@chrome://selenium-ide/content/tools.js -> file:///L:/integro/deploy/tests/SeleniumIDE/000.UserExtensions/selblocks.js?1499335510613:598:17 $$.fn.interceptReplace/targetObj[targetFnName]@chrome://selenium-ide/content/tools.js -> file:///L:/integro/deploy/tests/SeleniumIDE/000.UserExtensions/selblocks.js?1499335510613:221:20 .nextCommand@chrome://selenium-ide/content/selenium-runner.js:217:19 TestLoop.prototype.continueTest@chrome://selenium-ide/content/selenium-core/scripts/selenium-executionloop.js:35:35 .start@chrome://selenium-ide/content/selenium-runner.js:194:5 start@chrome://selenium-ide/content/selenium-runner.js:418:3 Debugger.prototype.start@chrome://selenium-ide/content/debugger.js:154:3 Editor.prototype.playCurrentTestCase@chrome://selenium-ide/content/editor.js:925:3 Editor.prototype.playTestSuite/<@chrome://selenium-ide/content/editor.js:977:7 Editor.prototype.playTestSuite@chrome://selenium-ide/content/editor.js:973:4 Editor.controller.doCommand@chrome://selenium-ide/content/editor.js:390:9 goDoCommand@chrome://global/content/globalOverlay.js:100:7 oncommand@chrome://selenium-ide/content/selenium-ide.xul:1:1

Selenium IDE 2.9.1 Firefox 50

What am I missing?

matthewkastor commented 7 years ago

The file was meant to run on the selenium rc server. The selenium-server-standalone.jar with the -htmlSuite option and -userExtensions options. There are some example bat files for launching it in the previous comments.

http://www.seleniumhq.org/docs/08_user_extensions.jsp#using-user-extensions-with-selenium-rc

I couldn't say whether there were updates to the selenium rc server that break this or not. It's been a few years since I tried using it. I've just been writing automated tests using the C# selenium.