|
| 1 | +import org.jenkinsci.plugins.pipeline.modeldefinition.Utils |
| 2 | + |
| 3 | +node { |
| 4 | + try { |
| 5 | + properties([ |
| 6 | + parameters([ |
| 7 | + credentials(credentialType: 'com.browserstack.automate.ci.jenkins.BrowserStackCredentials', defaultValue: '', description: 'Select your BrowserStack Username', name: 'BROWSERSTACK_USERNAME', required: true), |
| 8 | + [$class: 'ExtensibleChoiceParameterDefinition', |
| 9 | + choiceListProvider: [ |
| 10 | + $class: 'TextareaChoiceListProvider', |
| 11 | + addEditedValue: false, |
| 12 | + choiceListText: '''bstack-single |
| 13 | +bstack-parallel |
| 14 | +bstack-local''', |
| 15 | + defaultChoice: 'bstack-single' |
| 16 | + ], |
| 17 | + description: 'Select the test you would like to run', |
| 18 | + editable: false, |
| 19 | + name: 'TEST_TYPE'] |
| 20 | + ]) |
| 21 | + ]) |
| 22 | + |
| 23 | + stage('Pull from Github') { |
| 24 | + dir('test') { |
| 25 | + git branch: 'review', changelog: false, poll: false, url: 'https://github.com/browserstack/browserstack-examples-robot.git' |
| 26 | + } |
| 27 | + dir('pipPackage') { |
| 28 | + git branch: 'develop_webdriver-framework_python', changelog: false, poll: false, url: 'https://github.com/browserstack/webdriver-framework.git' |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + stage('Start Local') { |
| 33 | + if ( "${params.TEST_TYPE}".contains('local') ) { |
| 34 | + dir('app') { |
| 35 | + git branch: 'master', url: 'https://github.com/browserstack/browserstack-demo-app' |
| 36 | + sh ''' |
| 37 | + npm install |
| 38 | + npm run build |
| 39 | + npm start & |
| 40 | + ''' |
| 41 | + } |
| 42 | + } else { |
| 43 | + Utils.markStageSkippedForConditional('Start Local') |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + stage('Install Dependencies'){ |
| 48 | + sh ''' |
| 49 | + pip3 install robotframework |
| 50 | + pip3 install robotframework-seleniumlibrary |
| 51 | + pip3 install browserstack |
| 52 | + pip3 install webdriver_manager |
| 53 | + pip3 install robotframework-pabot |
| 54 | + ''' |
| 55 | + } |
| 56 | + |
| 57 | + stage('Run Test(s)') { |
| 58 | + browserstack(credentialsId: "${params.BROWSERSTACK_USERNAME}") { |
| 59 | + |
| 60 | + sh ''' |
| 61 | + cd pipPackage/selenium |
| 62 | +
|
| 63 | + pip3 install wheel |
| 64 | + pip3 install . |
| 65 | + ''' |
| 66 | + |
| 67 | + if ( "${params.TEST_TYPE}".contains('parallel') ) { |
| 68 | + sh ''' |
| 69 | + cd test |
| 70 | + export CONFIG_FILE_PATH=`pwd`/'resources/conf/caps/bstack-config.yaml' |
| 71 | + python3 -m robot --variable testType:bstack-single . |
| 72 | +
|
| 73 | + //pabot --testlevelsplit --verbose --variable testType:bstack-single --suite product . |
| 74 | +
|
| 75 | + ''' |
| 76 | + else if ( "${params.TEST_TYPE}".contains('local') ) { |
| 77 | + sh ''' |
| 78 | + cd test |
| 79 | + export CONFIG_FILE_PATH=`pwd`/'resources/conf/caps/bstack-local-config.yaml' |
| 80 | + python3 -m robot --variable testType:bstack-single . |
| 81 | + ''' |
| 82 | + } |
| 83 | + else{ |
| 84 | + sh ''' |
| 85 | + cd test |
| 86 | + export CONFIG_FILE_PATH=`pwd`/'resources/conf/caps/bstack-config.yaml' |
| 87 | + python3 -m robot --variable testType:bstack-single . |
| 88 | +
|
| 89 | + ''' |
| 90 | + |
| 91 | + } |
| 92 | + |
| 93 | + } |
| 94 | + } |
| 95 | + } catch (e) { |
| 96 | + currentBuild.result = 'FAILURE' |
| 97 | + echo e |
| 98 | + } finally { |
| 99 | + stage('Publish Results'){ |
| 100 | + browserStackReportPublisher 'automate' |
| 101 | + } |
| 102 | + } |
| 103 | +} |
0 commit comments