1. Template project
Let the items in the template become template items for the time being. As mentioned in the previous article, this is a project about vowels in English, counting how many vowels are contained in a word
< img alt="Share a picture" src="/wp-content/uploads/images/architecture/auto-test/1626814342672.png" >
two. Contexts< /span>
Note that there are the following lines in the example.spec file, and the step in line 11 means Context step
Context, official website The explanation given is that one or more context steps are located in front of all scenes in a spec file. It is a necessary link to execute the scene. The context can set data before the scene runs, and it can also act as a setup or teardown function. The context is executed in front of each scene
In the above example, the context step will log in as Mike, jump to the project page, and then execute the scenario of deleting a single project and deleting multiple projects. The execution order is:
Scene 1:
1. Log in as Mike and jump to the project page
2. Delete a single item
Scene two:
3. Log in as Mike and jump to the project page
4. Delete multiple items
The instructions given It’s easy to understand, it’s actually a bit similar to the setUpClass in unittest, the initialization of the environment. If, as we said earlier, a scene is equivalent to a class, this is somewhat similar to the initialization of the class __init__
Looking back at the template project example, there are two scenes Vowel counts in single word and Vowel counts in multiple word. The step in the first scene is The word “gauge” has “3” vowels. The step in the two scenes is a table listing word and Vowel Count. In fact, it can be understood that word is actually the actual parameter of the method, and the value corresponding to Vowel Count is the expected result corresponding to this actual parameter. This makes it easy to understand why the method should be parameterized:@step(“The word
But when we look at the step_impl.py file, we can’t really feel the execution order of the context, because the definition of the method is completely messy. The method on the context is in lines 19-22, and the one in the scene The method is in lines 14-16. This is not like setUpClass or __init__ constructor, in front of other methods inside the class
1 from getgauge.python import step, before_scenario, Messages
2
3 vowels = ["a", "e", "i", "o", "< span style="color: #800000;">u"]
4
5
6 def number_of_vowels(word):
7 return len([elem for elem in list(word) if span> elem in vowels])
8
9
10 # --------------------------
11 # Gauge step implementations
12 # --------------------------
13
14 @step("The wordhas ")vowels.
15 def assert_no_of_vowels_in(word, number):
16 assert str(number) == str(number_of_vowels(word))
17
18
19 @step("Vowels in English language are. ")
20 def assert_default_vowels(given_vowels):
21 Messages.write_message("Given vowels are {0}".format( given_vowels))
22 assert given_vowels == "".join(vowels)
23
24
25 @step("Almost all words have vowels")
26 def assert_words_vowel_count(table):
27 actual = [str(number_of_vowels(word)) for span> word in table.get_column_values_with_name("Word")]
28 expected = [str(count) for count in table.get_column_values_with_name(" Vowel Count")]
29 assert expected == actual
30
31
32 # ---------------
33 # Execution Hooks
34 # ---------------
35
36 @before_scenario()
37 def before_scenario_hook():
38 assert "".join(vowels) == "aeiou"Regarding the execution order, it can be verified only by checking the test report. The context step is executed before each scene in the test report is run. This is obvious
Reference article< /h1>
https://docs.gauge.org/latest/writing-specifications.html#longstart-context span>
Scene 1:
1. Log in as Mike and jump to the project page
2. Delete a single item
Scene two:
3. Log in as Mike and jump to the project page
4. Delete multiple items1 from getgauge.python import step, before_scenario, Messages
2
3 vowels = ["a", "e", "i", "o", "< span style="color: #800000;">u"]
4
5
6 def number_of_vowels(word):
7 return len([elem for elem in list(word) if span> elem in vowels])
8
9
10 # --------------------------
11 # Gauge step implementations
12 # --------------------------
13
14 @step("The wordhas ")vowels.
15 def assert_no_of_vowels_in(word, number):
16 assert str(number) == str(number_of_vowels(word))
17
18
19 @step("Vowels in English language are. ")
20 def assert_default_vowels(given_vowels):
21 Messages.write_message("Given vowels are {0}".format( given_vowels))
22 assert given_vowels == "".join(vowels)
23
24
25 @step("Almost all words have vowels")
26 def assert_words_vowel_count(table):
27 actual = [str(number_of_vowels(word)) for span> word in table.get_column_values_with_name("Word")]
28 expected = [str(count) for count in table.get_column_values_with_name(" Vowel Count")]
29 assert expected == actual
30
31
32 # ---------------
33 # Execution Hooks
34 # ---------------
35
36 @before_scenario()
37 def before_scenario_hook():
38 assert "".join(vowels) == "aeiou"WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 598 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC