Selenium: a stored variable is not considered in test cases when running a test suite from the command line

I have a test suite with three test cases, of which the first test case contains all the variables needed in the other 2 test cases (something like a dataset for a test suite)

All this time, when I ran tests in the Selenium IDE (manually loaded the test suite into the IDE and then started), everything was in order.

But I need a report to run a test case, so now I use the command below to run testuite
java -jar "selenium-server jar path" -htmlSuite "* firefox" "baseurl" "TestSuite path" "The result file" Path "

Now the problem is while executing a set of tests from the propmt command, variables stored in the first test file, not taken into account in the second test example, etc.

So can someone help me solve this problem.

+4
source share
3 answers

Open archive: selenium-server.jar \ core \ scripts \ Find selenium-testrunner.js Find and delete the following code from the file:

storedVars = new Object(); storedVars.nbsp = String.fromCharCode(160); storedVars.space = ' '; 
+2
source

This issue is a known bug. So you need to open selenium-server.jar or rc jar in something like 7zip (which I use) and find the following file:

selenium-server.jar\core\scripts\selenium-testrunner.js.

7zip will let you update this on the fly, and you just need to move the following code:

storedVars = new Object();
storedVars.nbsp = String.fromCharCode(160);
storedVars.space = ' ';

from the start of the startTest function to the start of the startTestSuite function.

A simple move where the stored variable object is initialized.

note , when you choose to edit in 7zip, it will open in notepad and you will see that the code is not formatted, so copy it and open in notepad ++ or something else, and then paste the change and save back.

you may also have a problem if you do this on windows, because there is a directory called β€œlicense” and a file named β€œLICENSE” in the RC root directory, and terrible windows identify this as a duplicate of the file, so before you do this above, change the file name "LICENSE" to something like "LICENSE_FILE".

+1
source

I solved this in my java code, for example:

 public class ExampleTest{ //main class of all testmodels private static String valueIneedToBeSendToAllTests; @Test public void test1(){ // steps of test String result = driver.webelement().getText(); setMyValue(result); } @Test public void test2(){ // steps of test String whatWasTheTextAgain = getMyValue(); } public String getMyValue(){ return valueIneedToBeSendToAllTests; } public void setMyValue(String valueToSet){ this.valueIneedToBeSendToAllTests = valueToSet; } } 

So, we repeat:

  • The value to be kept is private and static
  • This value is the value of the main class not as one of the tests.
  • Setters and getters matter. In other ways, it harmed for me.
0
source

All Articles