Best Cucumber Common Library code snippet using TestCase
test.php
Source:test.php
1<style type="text/css">2.pass {color: green;}3.fail {color: red;}4table.result {5 font-family: verdana,arial,sans-serif;6 font-size:11px;7 color:#333333;8 border-width: 1px;9 border-color: #666666;10 border-collapse: collapse;11}12table.result td {13 border-width: 1px;14 padding: 8px;15 border-style: solid;16 border-color: #666666;17 background-color: #ffffff;18 width: 400px;19}20table.result tr td:first-child {21 border-width: 1px;22 padding: 8px;23 border-style: solid;24 border-color: #666666;25 background-color: #dedede;26 width: 50px;27}28</style>29<?php30require_once 'ja.cssjanus.php';31$test = '';32$testcase = '';33$shouldbe = '';34$swap_ltr_rtl_in_url = False;35$swap_left_right_in_url = False;36function test () {37 global $test, $testcase, $shouldbe, $swap_ltr_rtl_in_url, $swap_left_right_in_url;38 $input = implode ("\n", $testcase);39 $expect = implode ("\n", $shouldbe);40 $output = JACSSJanus::transform ($input, $swap_ltr_rtl_in_url, $swap_left_right_in_url);41 $pass = ($output == $expect);42 $result = $pass ? '<span class="pass">pass</span>' : '<span class="fail">fail</span>';43?>44 <h2 class="<?php echo $pass ? 'pass':'fail' ?>"><?php echo $test ?></h2>45 <table class="result">46 <tr><td>Input</td><td><?php echo str_replace("\n", "<br />\n", $input) ?></td></tr>47 <tr><td>Expect</td><td><?php echo str_replace("\n", "<br />\n", $expect) ?></td></tr>48 <tr><td>Output</td><td><?php echo str_replace("\n", "<br />\n", $output) ?></td></tr>49 <tr><td>Result</td><td><?php echo $result ?></td></tr>50 </table>51 <br /><br />52<?php53}54$test = 'testPreserveComments';55$testcase = array('/* left /* right */left: 10px');56$shouldbe = array('/* left /* right */right: 10px');57test();58$testcase = array('/*left*//*left*/left: 10px');59$shouldbe = array('/*left*//*left*/right: 10px');60test();61$testcase = array('/* Going right is cool */\n#test {left: 10px}');62$shouldbe = array('/* Going right is cool */\n#test {right: 10px}');63$testcase = array('/* padding-right 1 2 3 4 */\n#test {left: 10px}\n/*right*/');64$shouldbe = array('/* padding-right 1 2 3 4 */\n#test {right: 10px}\n/*right*/');65test();66$testcase = array('/** Two line comment\n * left\n \*/\n#test {left: 10px}');67$shouldbe = array('/** Two line comment\n * left\n \*/\n#test {right: 10px}');68test();69$test = 'testPositionAbsoluteOrRelativeValues';70$testcase = array('left: 10px');71$shouldbe = array('right: 10px');72test();73$test = 'testFourNotation';74$testcase = array('padding: .25em 15px 0pt 0ex');75$shouldbe = array('padding: .25em 0ex 0pt 15px');76test();77$testcase = array('margin: 1px -4px 3px 2px');78$shouldbe = array('margin: 1px 2px 3px -4px');79test();80$testcase = array('padding:0 15px .25em 0');81$shouldbe = array('padding:0 0 .25em 15px');82test();83$testcase = array('padding: 1px 4.1grad 3px 2%');84$shouldbe = array('padding: 1px 2% 3px 4.1grad');85test();86$testcase = array('padding: 1px 2px 3px auto');87$shouldbe = array('padding: 1px auto 3px 2px');88test();89$testcase = array('padding: 1px inherit 3px auto');90$shouldbe = array('padding: 1px auto 3px inherit');91test();92# not really four notation93$testcase = array('#settings td p strong');94$shouldbe = $testcase;95test();96$test = 'testThreeNotation';97$testcase = array('margin: 1em 0 .25em');98$shouldbe = array('margin: 1em 0 .25em');99test();100$testcase = array('margin:-1.5em 0 -.75em');101$shouldbe = array('margin:-1.5em 0 -.75em');102test();103$test = 'testTwoNotation';104$testcase = array('padding: 1px 2px');105$shouldbe = array('padding: 1px 2px');106test();107$test = 'testOneNotation';108$testcase = array('padding: 1px');109$shouldbe = array('padding: 1px');110test();111$test = 'testDirection';112# we don't want direction to be changed other than in body113$testcase = array('direction: ltr');114$shouldbe = array('direction: ltr');115test();116# we don't want direction to be changed other than in body117$testcase = array('direction: rtl');118$shouldbe = array('direction: rtl');119test();120# we don't want direction to be changed other than in body121$testcase = array('input { direction: ltr }');122$shouldbe = array('input { direction: ltr }');123test();124$testcase = array('body { direction: ltr }');125$shouldbe = array('body { direction: rtl }');126test();127$testcase = array('body { padding: 10px; direction: ltr; }');128$shouldbe = array('body { padding: 10px; direction: rtl; }');129test();130$testcase = array('body { direction: ltr } .myClass { direction: ltr }');131$shouldbe = array('body { direction: rtl } .myClass { direction: ltr }');132test();133$testcase = array('body{\n direction: ltr\n}');134$shouldbe = array('body{\n direction: rtl\n}');135test();136$test = 'testDoubleDash';137$testcase = array('border-left-color: red');138$shouldbe = array('border-right-color: red');139test();140$testcase = array('border-right-color: red');141$shouldbe = array('border-left-color: red');142test();143# This is for compatibility strength, in reality CSS has no properties144# that are currently like this.145$test = 'testCSSProperty';146$testcase = array('alright: 10px');147$shouldbe = array('alright: 10px');148test();149$testcase = array('alleft: 10px');150$shouldbe = array('alleft: 10px');151test();152$test = 'testFloat';153$testcase = array('float: right');154$shouldbe = array('float: left');155test();156$testcase = array('float: left');157$shouldbe = array('float: right');158test();159$test = 'testUrlWithFlagOff';160$swap_ltr_rtl_in_url = False;161$swap_left_right_in_url = False;162$testcase = array('background: url(/foo/bar-left.png)');163$shouldbe = array('background: url(/foo/bar-left.png)');164test();165$testcase = array('background: url(/foo/left-bar.png)');166$shouldbe = array('background: url(/foo/left-bar.png)');167test();168$testcase = array('url("http://www.blogger.com/img/triangle_ltr.gif")');169$shouldbe = array('url("http://www.blogger.com/img/triangle_ltr.gif")');170test();171$testcase = array("url('http://www.blogger.com/img/triangle_ltr.gif')");172$shouldbe = array("url('http://www.blogger.com/img/triangle_ltr.gif')");173test();174$testcase = array("url('http://www.blogger.com/img/triangle_ltr.gif' )");175$shouldbe = array("url('http://www.blogger.com/img/triangle_ltr.gif' )");176test();177$testcase = array('background: url(/foo/bar.left.png)');178$shouldbe = array('background: url(/foo/bar.left.png)');179test();180$testcase = array('background: url(/foo/bar-rtl.png)');181$shouldbe = array('background: url(/foo/bar-rtl.png)');182test();183$testcase = array('background: url(/foo/bar-rtl.png); left: 10px');184$shouldbe = array('background: url(/foo/bar-rtl.png); right: 10px');185test();186$testcase = array('background: url(/foo/bar-right.png); direction: ltr');187$shouldbe = array('background: url(/foo/bar-right.png); direction: ltr');188test();189$testcase = array('background: url(/foo/bar-rtl_right.png);',190 'left:10px; direction: ltr');191$shouldbe = array('background: url(/foo/bar-rtl_right.png);',192 'right:10px; direction: ltr');193test();194$test = 'testUrlWithFlagOn';195$swap_ltr_rtl_in_url = True;196$swap_left_right_in_url = True;197$testcase = array('background: url(/foo/bar-left.png)');198$shouldbe = array('background: url(/foo/bar-right.png)');199test();200$testcase = array('background: url(/foo/left-bar.png)');201$shouldbe = array('background: url(/foo/right-bar.png)');202test();203$testcase = array('url("http://www.blogger.com/img/triangle_ltr.gif")');204$shouldbe = array('url("http://www.blogger.com/img/triangle_rtl.gif")');205test();206$testcase = array("url('http://www.blogger.com/img/triangle_ltr.gif')");207$shouldbe = array("url('http://www.blogger.com/img/triangle_rtl.gif')");208test();209$testcase = array("url('http://www.blogger.com/img/triangle_ltr.gif' )");210$shouldbe = array("url('http://www.blogger.com/img/triangle_rtl.gif' )");211test();212$testcase = array('background: url(/foo/bar.left.png)');213$shouldbe = array('background: url(/foo/bar.right.png)');214test();215$testcase = array('background: url(/foo/bright.png)');216$shouldbe = array('background: url(/foo/bright.png)');217test();218$testcase = array('background: url(/foo/bar-rtl.png)');219$shouldbe = array('background: url(/foo/bar-ltr.png)');220test();221$testcase = array('background: url(/foo/bar-rtl.png); left: 10px');222$shouldbe = array('background: url(/foo/bar-ltr.png); right: 10px');223test();224$testcase = array('background: url(/foo/bar-right.png); direction: ltr');225$shouldbe = array('background: url(/foo/bar-left.png); direction: ltr');226test();227$testcase = array('background: url(/foo/bar-rtl_right.png);',228 'left:10px; direction: ltr');229$shouldbe = array('background: url(/foo/bar-ltr_left.png);',230 'right:10px; direction: ltr');231test();232$test = 'testPadding';233$testcase = array('padding-right: bar');234$shouldbe = array('padding-left: bar');235test();236$testcase = array('padding-left: bar');237$shouldbe = array('padding-right: bar');238test();239$test = 'testMargin';240$testcase = array('margin-left: bar');241$shouldbe = array('margin-right: bar');242test();243$testcase = array('margin-right: bar');244$shouldbe = array('margin-left: bar');245test();246$test = 'testBorder';247$testcase = array('border-left: bar');248$shouldbe = array('border-right: bar');249test();250$testcase = array('border-right: bar');251$shouldbe = array('border-left: bar');252test();253$test = 'testCursor';254$testcase = array('cursor: e-resize');255$shouldbe = array('cursor: w-resize');256test();257$testcase = array('cursor: w-resize');258$shouldbe = array('cursor: e-resize');259test();260$testcase = array('cursor: se-resize');261$shouldbe = array('cursor: sw-resize');262test();263$testcase = array('cursor: sw-resize');264$shouldbe = array('cursor: se-resize');265test();266$testcase = array('cursor: ne-resize');267$shouldbe = array('cursor: nw-resize');268test();269$testcase = array('cursor: nw-resize');270$shouldbe = array('cursor: ne-resize');271test();272$test = 'testBGPosition';273$testcase = array('background: url(/foo/bar.png) top left');274$shouldbe = array('background: url(/foo/bar.png) top right');275test();276$testcase = array('background: url(/foo/bar.png) top right');277$shouldbe = array('background: url(/foo/bar.png) top left');278test();279$testcase = array('background-position: top left');280$shouldbe = array('background-position: top right');281test();282$testcase = array('background-position: top right');283$shouldbe = array('background-position: top left');284test();285$test = 'testBGPositionPercentage';286$testcase = array('background-position: 100% 40%');287$shouldbe = array('background-position: 0% 40%');288test();289$testcase = array('background-position: 0% 40%');290$shouldbe = array('background-position: 100% 40%');291test();292$testcase = array('background-position: 23% 0');293$shouldbe = array('background-position: 77% 0');294test();295$testcase = array('background-position: 23% auto');296$shouldbe = array('background-position: 77% auto');297test();298$testcase = array('background-position-x: 23%');299$shouldbe = array('background-position-x: 77%');300test();301$testcase = array('background-position-y: 23%');302$shouldbe = array('background-position-y: 23%');303test();304$testcase = array('background:url(../foo-bar_baz.2008.gif) no-repeat 75% 50%');305$shouldbe = array('background:url(../foo-bar_baz.2008.gif) no-repeat 25% 50%');306test();307$testcase = array('.test { background: 10% 20% } .test2 { background: 40% 30% }');308$shouldbe = array('.test { background: 90% 20% } .test2 { background: 60% 30% }');309test();310$testcase = array('.test { background: 0% 20% } .test2 { background: 40% 30% }');311$shouldbe = array('.test { background: 100% 20% } .test2 { background: 60% 30% }');312test();313$test = 'testDirectionalClassnames';314/*315"""Makes sure we don't unnecessarily destroy classnames with tokens in them.316Despite the fact that that is a bad classname in CSS, we don't want to317break anybody.318"""319*/320$testcase = array('.column-left { float: left }');321$shouldbe = array('.column-left { float: right }');322test();323$testcase = array('#bright-light { float: left }');324$shouldbe = array('#bright-light { float: right }');325test();326$testcase = array('a.left:hover { float: left }');327$shouldbe = array('a.left:hover { float: right }');328test();329#tests newlines330$testcase = array("#bright-left,\n.test-me { float: left }");331$shouldbe = array("#bright-left,\n.test-me { float: right }");332test();333#tests newlines334$testcase = array("#bright-left,", '.test-me { float: left }');335$shouldbe = array("#bright-left,", '.test-me { float: right }');336test();337#tests multiple names and commas338$testcase = array('div.leftpill, div.leftpillon {margin-right: 0 !important}');339$shouldbe = array('div.leftpill, div.leftpillon {margin-left: 0 !important}');340test();341$testcase = array('div.left > span.right+span.left { float: left }');342$shouldbe = array('div.left > span.right+span.left { float: right }');343test();344$testcase = array('.thisclass .left .myclass {background:#fff;}');345$shouldbe = array('.thisclass .left .myclass {background:#fff;}');346test();347$testcase = array('.thisclass .left .myclass #myid {background:#fff;}');348$shouldbe = array('.thisclass .left .myclass #myid {background:#fff;}');349test();350$test = 'testLongLineWithMultipleDefs';351$testcase = array('body{direction:rtl;float:right}352 .b2{direction:ltr;float:right}');353$shouldbe = array('body{direction:ltr;float:left}354 .b2{direction:ltr;float:left}');355test();356$test = 'testNoFlip';357# """Tests the /* @noflip */ annotation on classnames."""358$testcase = array('/* @noflip */ div { float: left; }');359$shouldbe = array('/* @noflip */ div { float: left; }');360test();361$testcase = array('/* @noflip */ div, .notme { float: left; }');362$shouldbe = array('/* @noflip */ div, .notme { float: left; }');363test();364$testcase = array('/* @noflip */ div { float: left; } div { float: left; }');365$shouldbe = array('/* @noflip */ div { float: left; } div { float: right; }');366test();367$testcase = array('/* @noflip */\ndiv { float: left; }\ndiv { float: left; }');368$shouldbe = array('/* @noflip */\ndiv { float: left; }\ndiv { float: right; }');369test();370# Test @noflip on single rules within classes371$testcase = array('div { float: left; /* @noflip */ float: left; }');372$shouldbe = array('div { float: right; /* @noflip */ float: left; }');373test();374$testcase = array('div\n{ float: left;\n/* @noflip */\n float: left;\n }');375$shouldbe = array('div\n{ float: right;\n/* @noflip */\n float: left;\n }');376test();377$testcase = array('div\n{ float: left;\n/* @noflip */\n text-align: left\n }');378$shouldbe = array('div\n{ float: right;\n/* @noflip */\n text-align: left\n }');379test();380$testcase = array('div\n{ /* @noflip */\ntext-align: left;\nfloat: left\n }');381$shouldbe = array('div\n{ /* @noflip */\ntext-align: left;\nfloat: right\n }');382test();383$testcase = array('/* @noflip */div{float:left;text-align:left;}div{float:left}');384$shouldbe = array('/* @noflip */div{float:left;text-align:left;}div{float:right}');385test();386$testcase = array('/* @noflip */','div{float:left;text-align:left;}a{foo:left}');387$shouldbe = array('/* @noflip */','div{float:left;text-align:left;}a{foo:right}');388test();389$test = 'testBorderRadiusNotation';390$testcase = array('border-radius: .25em 15px 0pt 0ex');391$shouldbe = array('border-radius: 15px .25em 0ex 0pt');392test();393$testcase = array('border-radius: 10px 15px 0px');394$shouldbe = array('border-radius: 15px 10px 15px 0px');395test();396$testcase = array('border-radius: 7px 8px');397$shouldbe = array('border-radius: 8px 7px');398test();399$testcase = array('border-radius: 5px');400$shouldbe = array('border-radius: 5px');401test();402$test = 'testGradientNotation';403$testcase = array('background-image: -moz-linear-gradient(#326cc1, #234e8c)');404$shouldbe = array('background-image: -moz-linear-gradient(#326cc1, #234e8c)');405test();406$testcase = array('background-image: -webkit-gradient(linear, 100% 0%, 0% 0%, from(#666666), to(#ffffff))');407$shouldbe = array('background-image: -webkit-gradient(linear, 100% 0%, 0% 0%, from(#666666), to(#ffffff))');408test();...
PrinterContents.php
Source:PrinterContents.php
2namespace NunoMaduro\Collision\Adapters\Phpunit;3use NunoMaduro\Collision\Exceptions\ShouldNotHappen;4use PHPUnit\Framework\AssertionFailedError;5use PHPUnit\Framework\Test;6use PHPUnit\Framework\TestCase;7use PHPUnit\Framework\TestSuite;8use PHPUnit\Framework\Warning;9use ReflectionObject;10use Symfony\Component\Console\Input\ArgvInput;11use Symfony\Component\Console\Output\ConsoleOutput;12use Throwable;13trait PrinterContents14{15 /**16 * Holds an instance of the style.17 *18 * Style is a class we use to interact with output.19 *20 * @var Style21 */22 private $style;23 /**24 * Holds the duration time of the test suite.25 *26 * @var Timer27 */28 private $timer;29 /**30 * Holds the state of the test31 * suite. The number of tests, etc.32 *33 * @var State34 */35 private $state;36 /**37 * If the test suite has ended before.38 *39 * @var bool40 */41 private $ended = false;42 /**43 * Creates a new instance of the listener.44 *45 * @param ConsoleOutput $output46 *47 * @throws \ReflectionException48 */49 public function __construct(ConsoleOutput $output = null)50 {51 if (intval(substr(\PHPUnit\Runner\Version::id(), 0, 1)) === 8) {52 parent::__construct();53 }54 $this->timer = Timer::start();55 $output = $output ?? new ConsoleOutput();56 ConfigureIO::of(new ArgvInput(), $output);57 $this->style = new Style($output);58 $dummyTest = new class() extends TestCase {59 };60 $this->state = State::from($dummyTest);61 }62 /**63 * {@inheritdoc}64 */65 public function addError(Test $testCase, Throwable $throwable, float $time): void66 {67 $testCase = $this->testCaseFromTest($testCase);68 $this->state->add(TestResult::fromTestCase($testCase, TestResult::FAIL));69 $this->style->writeError($this->state, $throwable);70 }71 /**72 * {@inheritdoc}73 */74 public function addWarning(Test $testCase, Warning $warning, float $time): void75 {76 $testCase = $this->testCaseFromTest($testCase);77 $this->state->add(TestResult::fromTestCase($testCase, TestResult::WARN, $warning->getMessage()));78 }79 /**80 * {@inheritdoc}81 */82 public function addFailure(Test $testCase, AssertionFailedError $error, float $time): void83 {84 $testCase = $this->testCaseFromTest($testCase);85 $this->state->add(TestResult::fromTestCase($testCase, TestResult::FAIL));86 $reflector = new ReflectionObject($error);87 if ($reflector->hasProperty('message')) {88 $message = trim((string) preg_replace("/\r|\n/", ' ', $error->getMessage()));89 $property = $reflector->getProperty('message');90 $property->setAccessible(true);91 $property->setValue($error, $message);92 }93 $this->style->writeError($this->state, $error);94 }95 /**96 * {@inheritdoc}97 */98 public function addIncompleteTest(Test $testCase, Throwable $t, float $time): void99 {100 $testCase = $this->testCaseFromTest($testCase);101 $this->state->add(TestResult::fromTestCase($testCase, TestResult::INCOMPLETE));102 }103 /**104 * {@inheritdoc}105 */106 public function addRiskyTest(Test $testCase, Throwable $t, float $time): void107 {108 $testCase = $this->testCaseFromTest($testCase);109 $this->state->add(TestResult::fromTestCase($testCase, TestResult::RISKY, $t->getMessage()));110 }111 /**112 * {@inheritdoc}113 */114 public function addSkippedTest(Test $testCase, Throwable $t, float $time): void115 {116 $testCase = $this->testCaseFromTest($testCase);117 $this->state->add(TestResult::fromTestCase($testCase, TestResult::SKIPPED, $t->getMessage()));118 }119 /**120 * {@inheritdoc}121 */122 public function startTestSuite(TestSuite $suite): void123 {124 if ($this->state->suiteTotalTests === null) {125 $this->state->suiteTotalTests = $suite->count();126 }127 }128 /**129 * {@inheritdoc}130 */131 public function endTestSuite(TestSuite $suite): void132 {133 if (!$this->ended && $this->state->suiteTotalTests === $this->state->testSuiteTestsCount()) {134 $this->ended = true;135 $this->style->writeCurrentRecap($this->state);136 $this->style->updateFooter($this->state);137 $this->style->writeRecap($this->timer);138 }139 }140 /**141 * {@inheritdoc}142 */143 public function startTest(Test $testCase): void144 {145 $testCase = $this->testCaseFromTest($testCase);146 // Let's check first if the testCase is over.147 if ($this->state->testCaseHasChanged($testCase)) {148 $this->style->writeCurrentRecap($this->state);149 $this->state->moveTo($testCase);150 }151 $this->style->updateFooter($this->state, $testCase);152 }153 /**154 * {@inheritdoc}155 */156 public function endTest(Test $testCase, float $time): void157 {158 $testCase = $this->testCaseFromTest($testCase);159 if (!$this->state->existsInTestCase($testCase)) {160 $this->state->add(TestResult::fromTestCase($testCase, TestResult::PASS));161 }162 }163 /**164 * Intentionally left blank as we output things on events of the listener.165 */166 public function write(string $content): void167 {168 // ..169 }170 /**171 * Returns a test case from the given test.172 *173 * Note: This printer is do not work with normal Test classes - only174 * with Test Case classes. Please report an issue if you think175 * this should work any other way.176 */177 private function testCaseFromTest(Test $test): TestCase178 {179 if (!$test instanceof TestCase) {180 throw new ShouldNotHappen();181 }182 return $test;183 }184}...
xcresult_to_junit_helper.rb
Source:xcresult_to_junit_helper.rb
1require 'fastlane_core/ui/ui'2require 'json'3require 'fileutils'4module Fastlane5 UI = FastlaneCore::UI unless Fastlane.const_defined?("UI")6 module Helper7 class XcresultToJunitHelper8 def self.load_object(xcresult_path, id)9 JSON.parse(FastlaneCore::CommandExecutor.execute(command: "xcrun xcresulttool get --format json --path #{xcresult_path} --id #{id}"))10 end11 def self.load_results(xcresult_path)12 JSON.parse(FastlaneCore::CommandExecutor.execute(command: "xcrun xcresulttool get --format json --path #{xcresult_path}"))13 end14 def self.fetch_screenshot(xcresult_path, output_path, file_name, id)15 unless File.directory?(output_path)16 FileUtils.mkdir(output_path)17 end18 FastlaneCore::CommandExecutor.execute(command: "xcrun xcresulttool export --path #{xcresult_path} --output-path \"#{output_path}/#{file_name}\" --id #{id} --type file")19 end20 def self.save_screenshot_mapping(map_hash, output_path)21 File.open("#{output_path}/map.json", 'w') do |f|22 f << map_hash.to_json23 end24 end25 def self.save_device_details_to_file(output_path, device_destination)26 device_udid = device_destination['targetDeviceRecord']['identifier']['_value']27 device_details = {28 'udid' => device_udid,29 'name' => device_destination['targetDeviceRecord']['modelName']['_value'],30 'os' => device_destination['targetDeviceRecord']['operatingSystemVersion']['_value']31 }.to_json32 junit_folder = "#{output_path}/ios-#{device_udid}.junit"33 FileUtils.rm_rf(junit_folder)34 FileUtils.mkdir_p("#{junit_folder}/attachments")35 File.open("#{junit_folder}/device.json", 'w') do |f|36 f << device_details37 end38 return junit_folder39 end40 def self.junit_file_start41 puts('<?xml version="1.0" encoding="UTF-8"?>')42 puts('<testsuites>')43 end44 def self.junit_file_end45 puts('</testsuites>')46 end47 def self.junit_suite_error(suite)48 puts("<testsuite name=#{suite[:name].encode(xml: :attr)} errors='1'>")49 puts("<error>#{suite[:error].encode(xml: :text)}</error>")50 end51 def self.junit_suite_start(suite)52 puts("<testsuite name=#{suite[:name].encode(xml: :attr)} tests='#{suite[:count]}' failures='#{suite[:failures]}' errors='#{suite[:errors]}'>")53 end54 def self.junit_suite_end55 puts('</testsuite>')56 end57 def self.junit_testcase_start(suite, testcase)58 print("<testcase name=#{testcase[:name].encode(xml: :attr)} classname=#{suite[:name].encode(xml: :attr)} time='#{testcase[:time]}'>")59 end60 def self.junit_testcase_end61 puts('</testcase>')62 end63 def self.junit_testcase_failure(testcase)64 puts("<failure message=#{testcase[:failure].encode(xml: :attr)}>#{testcase[:failure_location].encode(xml: :text)}</failure>")65 end66 def self.junit_testcase_error(testcase)67 puts("<error>#{testcase[:error].encode(xml: :text)}</error>")68 end69 def self.junit_testcase_performance(testcase)70 puts("<system-out>#{testcase[:performance]}</system-out>")71 end72 def self.generate_junit(junit_folder, test_suites)73 File.open("#{junit_folder}/results.xml", 'w') do |fo|74 old_stdout = $stdout75 $stdout = fo76 Helper::XcresultToJunitHelper.junit_file_start77 test_suites.each do |suite|78 if suite[:error]79 Helper::XcresultToJunitHelper.junit_suite_error(suite)80 else81 Helper::XcresultToJunitHelper.junit_suite_start(suite)82 suite[:cases].each do |testcase|83 Helper::XcresultToJunitHelper.junit_testcase_start(suite, testcase)84 if testcase[:failure]85 Helper::XcresultToJunitHelper.junit_testcase_failure(testcase)86 elsif testcase[:error]87 Helper::XcresultToJunitHelper.junit_testcase_error(testcase)88 end89 if testcase[:performance]90 Helper::XcresultToJunitHelper.junit_testcase_performance(testcase)91 end92 Helper::XcresultToJunitHelper.junit_testcase_end93 end94 end95 Helper::XcresultToJunitHelper.junit_suite_end96 end97 Helper::XcresultToJunitHelper.junit_file_end98 $stdout = old_stdout99 end100 end101 end102 end103end...
testcases_controller.rb
Source:testcases_controller.rb
1class TestcasesController < ApplicationController2 include TestcasesHelper3 def index4 @project = Project.find(params[:project_id])5 @testcases = Testcase.where(:project_identifier => params[:project_id]) #@project6 # This variable is used to build the testcase tree7 @testcase_tree = {}8 # For each testcase t9 @testcases.each do |t|10 # add t to the tree11 add @testcase_tree, t.path.split("."), t12 end13 # This is to allow different formats for the server response14 # The format depends on the http request, which may contain an15 # "Accept: ..." attribute to ask for a preferred response type.16 respond_to do |format|17 format.html18 # The following just plainly renders the testcase_tree variable as a json object19 format.json { render json: @testcase_tree }20 end21 end22 def show23 @project = Project.find(params[:project_id])24 @testcases_available = Testcase.where(:project_identifier => @project.identifier)25 @testcase = Testcase.find(params[:id])26 render 'edit'27 end28 def progress29 testcases = Testcase.joins(:testcase_issue_relations).where("testcase_issue_relations.issue_id = ?", params[:issue_id])30 res = {}31 testcases.each do |t|32 s = t.status.downcase33 res[s] ||= 034 res[s] += 135 end36 render json: res37 end38 def new39 # Remember to put this in front of (every) controller method, so that40 # redmine can show the project menu links41 @project = Project.find(params[:project_id])42 @testcases_available = Testcase.where(:project_identifier => params[:project_id])43 @testcase = Testcase.new44 end45 def edit46 @project = Project.find(params[:project_id])47 @testcase = Testcase.find(params[:id])48 end49 def toggle50 @project = Project.find(params[:project_id])51 @testcase = Testcase.find(params[:id])52 if (@testcase.status.downcase == "passed")53 @testcase.status = "failed"54 else55 @testcase.status = "passed"56 end57 @testcase.time_last_run = DateTime.now58 @testcase.save59 render json: @testcase60 end61 def create62 @project = Project.find(params[:project_id])63 testcase_input = testcase_params64 testcase_input["time_last_run"] = DateTime.now65 testcase_input["status"] = "FAILED"66 testcase_input["test_type"] = "MANUAL"67 testcase_input["project_identifier"] = @project.identifier68 @testcase = Testcase.new(testcase_input)69 @testcase.path = params[:new_path] unless params[:new_path].empty?70 if @testcase.save71 redirect_to :action => 'index'72 else73 @testcases_available = Testcase.where(:project_identifier => params[:project_id])74 render 'new'75 end76 end77 def update78 @project = Project.find(params[:project_id])79 @testcase = Testcase.find(params[:id])80 testcase_input = testcase_params81 testcase_input["time_last_run"] = DateTime.now82 testcase_input["test_type"] = "MANUAL"83 testcase_input["path"] = params[:new_path] unless params[:new_path].empty?84 if @testcase.update(testcase_input)85 redirect_to :action => 'index'86 else87 @testcases_available = Testcase.where(:project_id => @project)88 render 'edit'89 end90 end91 def destroy92 @project = Project.find(params[:project_id])93 @testcase = Testcase.find(params[:id])94 @testcase.destroy95 redirect_to :action => 'index'96 end97 private98 def testcase_params99 params.require(:testcase).permit(:name, :description, :path)100 end101end...
configuration_spec.rb
Source:configuration_spec.rb
...5 def config6 @config ||= Configuration.new7 end8 describe "#use_transactional_fixtures" do9 it "should return ActiveSupport::TestCase.use_transactional_fixtures" do10 config.use_transactional_fixtures.should == ActiveSupport::TestCase.use_transactional_fixtures11 end12 it "should set ActiveSupport::TestCase.use_transactional_fixtures to false" do13 ActiveSupport::TestCase.should_receive(:use_transactional_fixtures=).with(false)14 config.use_transactional_fixtures = false15 end16 it "should set ActiveSupport::TestCase.use_transactional_fixtures to true" do17 ActiveSupport::TestCase.should_receive(:use_transactional_fixtures=).with(true)18 config.use_transactional_fixtures = true19 end20 end21 describe "#use_instantiated_fixtures" do22 it "should return ActiveSupport::TestCase.use_transactional_fixtures" do23 config.use_instantiated_fixtures.should == ActiveSupport::TestCase.use_instantiated_fixtures24 end25 it "should set ActiveSupport::TestCase.use_instantiated_fixtures to false" do26 ActiveSupport::TestCase.should_receive(:use_instantiated_fixtures=).with(false)27 config.use_instantiated_fixtures = false28 end29 it "should set ActiveSupport::TestCase.use_instantiated_fixtures to true" do30 ActiveSupport::TestCase.should_receive(:use_instantiated_fixtures=).with(true)31 config.use_instantiated_fixtures = true32 end33 end34 describe "#fixture_path" do35 it "should default to RAILS_ROOT + '/spec/fixtures'" do36 config.fixture_path.should == RAILS_ROOT + '/spec/fixtures'37 ActiveSupport::TestCase.fixture_path.should == RAILS_ROOT + '/spec/fixtures'38 ActionController::IntegrationTest.fixture_path.should == RAILS_ROOT + '/spec/fixtures'39 end40 it "should set fixture_path" do41 config.fixture_path = "/new/path"42 config.fixture_path.should == "/new/path"43 ActiveSupport::TestCase.fixture_path.should == "/new/path"44 ActionController::IntegrationTest.fixture_path.should == "/new/path"45 end46 end47 describe "#global_fixtures" do48 it "should set fixtures on TestCase" do49 ActiveSupport::TestCase.should_receive(:fixtures).with(:blah)50 config.global_fixtures = [:blah]51 end52 end53 54 end55 end56end...
TestCase
Using AI Code Generation
1use Cucumber\CommonTestCase;2use Cucumber\Gherkin\Node\PyStringNode;3use Cucumber\Gherkin\Node\TableNode;4use Cucumber\Gherkin\Node\ScenarioInterface;5use Cucumber\Gherkin\Node\StepNode;6use Cucumber\Gherkin\Node\StepContainerInterface;7use Cucumber\Gherkin\Node\FeatureNode;8use Cucumber\Gherkin\Node\BackgroundNode;9use Cucumber\Gherkin\Node\OutlineNode;10use Cucumber\Gherkin\Node\ExamplesNode;11use Cucumber\Gherkin\Node\RowNode;12use Cucumber\Gherkin\Node\PyStringNode;13use Cucumber\Gherkin\Node\TagNode;14use Cucumber\Gherkin\Node\CommentNode;15use Cucumber\Gherkin\Node\FeatureInterface;16use Cucumber\Gherkin\Node\BackgroundInterface;17use Cucumber\Gherkin\Node\ScenarioInterface;
TestCase
Using AI Code Generation
1use Cucumber\CommonBundle\Features\Context\CucumberCommonContext;2{3}4use Cucumber\CommonBundle\Features\Context\CucumberCommonContext;5{6}7use Cucumber\CommonBundle\Features\Context\CucumberCommonContext;8{9}10use Cucumber\CommonBundle\Features\Context\CucumberCommonContext;11{12}13use Cucumber\CommonBundle\Features\Context\CucumberCommonContext;14{15}16use Cucumber\CommonBundle\Features\Context\CucumberCommonContext;17{18}19use Cucumber\CommonBundle\Features\Context\CucumberCommonContext;20{21}22use Cucumber\CommonBundle\Features\Context\CucumberCommonContext;23{24}25use Cucumber\CommonBundle\Features\Context\CucumberCommonContext;26{27}28use Cucumber\CommonBundle\Features\Context\CucumberCommonContext;29{30}31use Cucumber\CommonBundle\Features\Context\CucumberCommonContext;32{33}34use Cucumber\CommonBundle\Features\Context\CucumberCommonContext;35{36}
TestCase
Using AI Code Generation
1use Cucumber\CommonTestCase;2class CucumberCommonTestCase extends CommonTestCase {3 public function testCucumberCommonTestCase() {4 $this->assertEquals(2, 2);5 }6}7use PHPUnit\Framework\TestCase;8class PHPUnitTestCase extends TestCase {9 public function testPHPUnitTestCase() {10 $this->assertEquals(3, 3);11 }12}13use Codeception\Test\Unit;14class CodeceptionTestCase extends Unit {15 public function testCodeceptionTestCase() {16 $this->assertEquals(4, 4);17 }18}19use Behat\Behat\Context\Context;20class BehatTestCase implements Context {21 public function testBehatTestCase() {22 return 5;23 }24}25use PhpSpec\ObjectBehavior;26class PHPSpecTestCase extends ObjectBehavior {27 public function testPHPSpecTestCase() {28 $this->shouldHaveType('PHPSpecTestCase');29 }30}31use PhpSpec\ObjectBehavior;32class PHPSpecTestCase extends ObjectBehavior {33 public function testPHPSpecTestCase() {34 $this->shouldHaveType('PHPSpecTestCase');35 }36}37use PhpSpec\ObjectBehavior;38class PHPSpecTestCase extends ObjectBehavior {39 public function testPHPSpecTestCase() {40 $this->shouldHaveType('PHPSpecTestCase');41 }42}43use PhpSpec\ObjectBehavior;44class PHPSpecTestCase extends ObjectBehavior {45 public function testPHPSpecTestCase() {46 $this->shouldHaveType('PHPSpecTestCase');47 }48}49use PhpSpec\ObjectBehavior;50class PHPSpecTestCase extends ObjectBehavior {51 public function testPHPSpecTestCase() {52 $this->shouldHaveType('PHPSpecTestCase');53 }54}
TestCase
Using AI Code Generation
1use Cucumber\CommonTestCase;2use Cucumber\Shared\Library\Common;3use Cucumber\Shared\Library\Browser;4use Cucumber\Shared\Library\Browser\BrowserFactory;5use Cucumber\Shared\Library\Browser\BrowserInterface;6use Cucumber\Shared\Library\Browser\BrowserInterfaceFactory;7use Cucumber\Shared\Library\Browser\BrowserManager;8use Cucumber\Shared\Library\Browser\BrowserManagerInterface;9use Cucumber\Shared\Library\Browser\BrowserManagerInterfaceFactory;10use Cucumber\Shared\Library\Browser\BrowserManagerTrait;11use Cucumber\Shared\Library\Browser\BrowserTrait;12use Cucumber\Shared\Library\Browser\BrowserInterfaceTrait;13use Cucumber\Shared\Library\Browser\BrowserInterfaceFactoryTrait;14use Cucumber\Shared\Library\Browser\BrowserManagerFactoryTrait;15use Cucumber\Shared\Library\Browser\BrowserManagerFactory;16use Cucumber\Shared\Library\Browser\BrowserInterfaceFactory;17use Cucumber\Shared\Library\Browser\BrowserFactoryTrait;18use Cucumber\Shared\Library\Browser\BrowserFactoryFactory;19use Cucumber\Shared\Library\Browser\BrowserFactoryFactoryTrait;20use Cucumber\Shared\Library\Browser\BrowserManagerInterfaceFactoryTrait;21use Cucumber\Shared\Library\Browser\BrowserManagerInterfaceFactory;22use Cucumber\Shared\Library\Browser\BrowserManagerFactoryFactory;
TestCase
Using AI Code Generation
1use Cucumber\CommonTestCase;2{3 public function test2()4 {5 }6}7use Cucumber\CommonTestCase;8{9 public function test3()10 {11 }12}13{14 {
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.
Test now for FreeGet 100 minutes of automation test minutes FREE!!